Why does AudioSource.time return Infinity in Unity 5.3?
I have a MovieTexture file in my project, and I want to keep track with the time based on the audio time. It works fine in Unity 5.1, but when I switch to 5.3, the AudioSource.time just returns Infinity. Does anyone know what has been changed. Here is a snippet of my code. Thank you!
 public void processVideoFile(){
         GameObject.Find("Video Frame").GetComponent<RawImage> ().texture = movie as MovieTexture;
         audio =  gameObject.GetComponent<AudioSource> ();
         audio.clip = movie.audioClip;
         movie.loop = false;
         videoIsProcessed = true;
     }
 
 void LateUpdate () {
         if (videoIsProcessed) {
             if (!movie.isPlaying && !pausing) {
                 gameObject.GetComponent<LessonManagerScript>().loadVideo(gameObject.GetComponent<LessonManagerScript>().currentButton);
                 playButton.gameObject.GetComponent<Image> ().enabled = true;
             }
             if(!pausing){
             timeStamp = audio.time + timeOffSet;
             }
             Debug.Log("Audio time is: "+audio.time+" and timeStamp is: "+timeStamp);
         }
     }
Answer by baopham · Jan 22, 2016 at 12:39 AM
I found a workaround it! I used a Stopwatch from System.Dianogtics to replace the audio.time.
However, this is a bug from Unity 5.3 (I'm pretty sure).
I also do have that exact same bug.
Is there anyone else affected by this?
That's pretty annoying.
Answer by wasam · Feb 02, 2016 at 10:44 AM
At the moment AudioClip.frequency seems to return 0 for MovieTextures.
This probably causes AudioSource.time to return "infinity".
I assume that AudioClip.frequency should return 48000 for MovieTextures, so you can create your own, corrected, version for now:
 public AudioSource audioSource;
 const int CLIP_FREQUENCY = 48000;
 
 void Update () {
     float time = audioSource.timeSamples * 1f / CLIP_FREQUENCY; 
 }
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                