- Home /
Problems with movies - delayed play or silent failure
I'm trying to get some large (1-2 minutes at 1920x1080 resolution) movies to work, and I'm having problems no matter what I try. I'm using Unity Pro.
In both cases I'm using a GUITexture object with an attached script to handle the actual movie playing. The GUITexture is setup to display the texture fullscreen.
The first method I attempted was to simply import the movies into Unity like regular assets, provide the references to the movies on the movie playing script, and simply select which texture to use. The script looked something like this:
public void Play(string whichMovie)
{
MovieTexture selectedMovie;
switch (whichMovie)
... set selectedMovie appropriately
guiTexture.texture = selectedMovie;
audio.clip = selectedMovie.audioClip;
selectedMovie.Play();
audio.Play();
}
This technically works, but there's a problem. The movie doesn't actually start playing when I call Play(). It seems like the movie doesn't properly get loaded until Play is called, and there's a huge delay. This wouldn't be a problem except that once the movie does start playing, it automatically syncs up to where it should be, cutting off the beginning few seconds of the clips.
I've tried various methods to wait until the video is actually ready to play, but nothing works. It seems like the delay is inevitable using this method.
So onto method 2: using the WWW class. My code for that is as follows:
public void Play(string whichMovie)
{
moviePath = "file://C:/agnes_build/" + which + ".ogg";
StartCoroutine(LoadAndPlayMovie());
}
IEnumerator LoadAndPlayMovie()
{
WWW w = new WWW(moviePath);
MovieTexture movie = w.movie;
while (!movie.isReadyToPlay)
yield return null;
guiTexture.texture = movie;
audio.clip = movie.audioClip;
movie.Play();
audio.Play();
}
At first it seemed the second method didn't work at all. But then I tried using the sample video provided by Unity (http://www.unity3d.com/webplayers/Movie/sample.ogg), and it worked. So now I realize that the code works, but for some reason the movies I'm encoding don't work in Unity, though they work outside of Unity just fine.
I used ffmpeg2theora as recommended in a different post, and I've also tried using Miro Video Converter (which is just using ffmpeg2theora under the hood I think), to no avail. The videos work just fine outside of Unity, but when I try to load them using the WWW class as above, they "load" immediately but have a duration of -1 seconds. They take no time to play and the code basically immediately finishes.
I've been scouring the forums, and I feel like I've already tried everything I can to get this working in an ideal way. At the moment I'm quite disappointed in getting a Pro license for the movie support. Any thoughts?
Answer by kmccmk9 · Jun 26, 2012 at 02:49 AM
I am having the same problem. Right now I'm troubleshooting by adding a second and a half to the beginning of my video. I noticed if you don't start playing the audio, it does not delay at all. Give it a shot.
Answer by Gawain · Jun 26, 2012 at 04:54 AM
The delay is because of the audio and video running seperety. You need to make it run video and have audio listener. If that dosent work run them from different scripts.
So don't call audio.Play()? Just have an audio listener component?
I do have an audio listener component on the object and that isn't working. So I should play video in one script and play audio in another script?
Okay I have done what you suggested and now it plays at the right time but the whole video plays sped up