MovieTexture playing faster than normal

I tried this code for playing my movie and movie’s audioclip,

var movTexture : MovieTexture;
var movAudio : AudioClip;

function OnGUI()
{
    GUI.DrawTexture (Rect (0,0, 480, 320),movTexture,ScaleMode.ScaleToFit );
    movTexture.Play();
    audio.clip = movAudio;
    audio.Play();
}

But when I played it,I found that the movie was playing faster than normal,I don’t know why?

Movies can play faster than normal if you set Time.timeScale to a value greater than one.

Video can play too fast if you are (accidentally, typically) setting audioSource.time every frame (even to its own value). Unity ends up speeding up video playback by 2-3x while the time counter still increases at 1x.

If you are just doing an audio file the same problem can result in crackly audio and a similar speed problem.

The way this happened to me was I tried to implement a seek bar (for audio… the player could handle both audio and video) but failed to realize the value changed event triggers for code changes as well as user changes (even if the interactivity setting of the Slider is false). So of course you want to update the seek bar every frame, but it triggers the value changed event when you do that, causing the audio to seek and the video to go wonky (since Unity can’t seek video).

Fix is easy if your only event handler for the value changed event is in the same class… use a boolean member to keep track of whether you are inside Update(). If so, ignore event callbacks without adjusting the audio source time property.

Video can play too fast if you are (accidentally, typically) setting audioSource.time every frame (even to its own value). Unity ends up speeding up video playback by 2-3x while the time counter still increases at 1x.

If you are just doing an audio file the same problem can result in crackly audio and a similar speed problem.

The way this happened to me was I tried to implement a seek bar (for audio… the player could handle both audio and video) but failed to realize the value changed event triggers for code changes as well as user changes (even if the interactivity setting of the Slider is false). So of course you want to update the seek bar every frame, but it triggers the value changed event when you do that, causing the audio to seek and the video to go wonky (since Unity can’t seek video).

Fix is easy if your only event handler for the value changed event is in the same class… use a boolean member to keep track of whether you are inside Update(). If so, ignore event callbacks without adjusting the audio source time property.