AudioSource.time 时间


var time : float

Description描述

Playback position in seconds.

以秒为单位的播放位置。

Use this to read current playback time or to seek to a new playback time.

使用这个读取当前播放时间或定位一个新的播放时间。

Be aware that: On a compressed audio track position does not necessary reflect the actual time in the track    Compressed audio is represented as a set of so-called packets.    The length of a packet depends on the compression settings and can quite often be 2-3 seconds per packet.  

注意:在压缩的音轨位置,并不一定反映实际时间,在压缩的音频被表示为一个所谓设置的数据包。一个数据包的长度取决于压缩设置,经常是每个包2-3秒。

参见:timeSamples变量

  • C#

  • JavaScript

using UnityEngine;using System.Collections;public class example : MonoBehaviour {void Update() {if (Input.GetKeyDown(KeyCode.Return)) {audio.Stop();audio.Play();}Debug.Log(audio.time);}}
// Prints the elapsed time in seconds the audio// source has been playing.// Press "Return" to start the song and see how the// time gets restarted..//以秒为单位,打印音频源已经播放所用的时间。//按Return键,开始播放,看看如何获取重新启动的时间function Update() {if(Input.GetKeyDown(KeyCode.Return)) {audio.Stop();audio.Play();}Debug.Log(audio.time);}


,