I am using a Unity WWW object to load in a movie file that is in ogg theora format, but I am experiencing some strangeness that I have not been able to figure out how to resolve.
For clarification, I have a folder in my Assets folder called "Movies/" which contains all my locally stored movie files.
A C# code snippet of my application follows, which is inside of a class method run with StartCoroutine:
WWW www = new WWW("file://" + Application.dataPath + "/Movies/" + movieName + ".ogg");
yield return www;
m_MovieTexture = www.movie;
if (m_MovieTexture == null)
{
DbgLog("Movie is NULL!");
return;
}
if (m_MovieTexture.isPlaying)
{
// Not sure how this can happen, but just in case....
m_MovieTexture.Stop();
}
else
{
if (www.error != null)
{
DbgLog("Error: " + www.error);
return;
}
DbgLog("Waiting to load " + www.url);
while (!m_MovieTexture.isReadyToPlay && !www.isDone)
{
yield return www;
}
DbgLog("Finished Loading");
if (www.isDone && !m_MovieTexture.isReadyToPlay)
{
DbgLog("Weirdness! File finished loading before movie was ready to play!");
}
}
m_MovieTexture.Play();
DbgLog("Playing video (" + m_MovieTexture.duration + " seconds)");
while (m_MovieTexture.isPlaying)
yield return null;
// be kind... rewind.
m_MovieTexture.Stop();
DbgLog("Finished Playing");
m_MovieTexture = null;
When the above code executes, the log statements within reveal that the www.isDone property returns true even while m_MovieTexture.isReadyToPlay returns false. Orignally, the while loop only waited on m_MovieTexture.isReadyToPlay, but that loop waited interminably, so the extra condition was added, which exposed what was really happening. The duration of the movie is also always -1, and finally, the above code does not appear to wait for the video to play to play at all, in spite of explicitly calling m_MovieTexture.Play() and then looping while m_MovieTexture.isPlaying is true, m_MovieTexture.isPlaying returns false immediately, and the movie never plays (there is code in the OnGUI method which displays the contents of m_MovieTexture if there is any and the movie is playing, but the problem seems to lie in the above code, not the OnGUI method).
Any thoughts on what I might be doing wrong here would be greatly appreciated.
Thanks in advance