I have a UI with a button and a panel. Clicking the button toggles the panel on and off :
GameObject.SetActive();
Now the panel element has a child which is a plane. This plane has the following components :
- mesh renderer
- videoPlay, a script I've written
- an audio source
The videoPlay script basically applies the MovieTexture to the plane's material, sets the plane's audioSource to the movie's audio clip, and starts audio and video.
public MovieTexture movie;
void Start() {
GetComponent<Renderer>().material.mainTexture = movie as MovieTexture;
GetComponent<AudioSource>().clip = movie.audioClip;
movie.Play();
GetComponent<AudioSource>().Play();
}
Now when at runtime I click the button (which hides the panel which is the plane's parent element), the audio and video stop as the plane disappears - which is expected behaviour.
When I reopen the panel though, the sound restarts right away but as if it were catching up for the time it was hidden (so it starts really fast and then comes back to regular speed) ; and the video is just frozen for - empirically and approximately - the same time the panel was hidden.
I've tried in the script - in Update() - messing with
if (!transform.parent.gameObject.activeSelf && movie.isPlaying)
{
movie.Pause();
GetComponent<AudioSource>().Pause();
}
for example, (and the same with Play() when it shows back up) but it doesn't seem to change anything.