Runtime MovieTexture in Web Player

Hi All,

I’m able to ‘successfully’ load a MovieTexture onto a Mesh (Plane). However I’m having two issues:

  1. MOST IMPORTANT ISSUE: The movie plays as expected but the sound does not.
  2. The movie appears squished rather than respecting it’s aspect ratio.

My question to the first item is how do I get the sound to play? After thorough forum surfing I’ve come across a thread that mentioned the necessity to apply the accompanying audio track to the gameobject audioclip object. However, that approach appears to only work with embedding movies at author time.
The second item, I assume, may have something to do with matrix transform(??). There is info on the forum but I’d welcome some quick tips on how to address that. :?

Here’s an example of what I’ve put together along with the code that I’m using: http://jessewolfe.com/unity/movietextest.html

If anyone has had experience with loading in movies at run-time I’d love some tips and/or example code to get me off the ground.

Thanks in advance for any help. :smile:

Cheers,

Jes

I’m not sure of a solution for this; I’ve always nested the movie within the Unity project (which makes for vrey large Unity outputs). This approach is very, very interesting…I’ll sure be interested to find out your solution.

It’d be even more fun if it’d drive a YouTube video; or some other “hosted on someone else’s server” video.

Thanks for your response, wadamw. :slight_smile:

I did just figure it out. Turns out that the gameobject (plane in this case) has to have a audio source component applied to it. Then in my code (viewable on that test page) I added two lines:

...

// Assign clip to audio source
// Sync playback with audio
audio.clip = mov.audioClip;//<------ADDED

	
// Play both movie  sound
mov.Play();

audio.Play();//<--------------------ADDED

...

Works great now. :smile:
http://jessewolfe.com/unity/movietextest.html

RE: your comment on youtube video, this example was pulled from youtube and converted to (*.ogg) .

Although the squishing still remains. I’ll dig around for more info on that now.

Jes

Currently when streaming the ogg file you need to wait until isReadyToPlay returns true before you assign the texture to a material. For gui textures that step is not necessary.

So, if I’m understanding this right I can do this:

a) Host a QT movie somewhere on my server (as a .mp4 perhaps).
b) Use the following script on a GUITexture:

function Start() {

					var u : String = "http://www.jessewolfe.com/unity/bball.ogg";

					// Start download
					var www : WWW = new WWW( u );

					renderer.material.mainTexture = [url]www.movie;[/url]
					
					var mov : MovieTexture = renderer.material.mainTexture as MovieTexture;

					while (!mov.isReadyToPlay) {
						yield;
					}

					// Assign clip to audio source
					// Sync playback with audio
					audio.clip = mov.audioClip;

					// Play both movie  sound
					mov.Play();
					audio.Play();
				}

c) Output the Unity project as a web player; and the videos will be called up only as needed?

[/quote]

The movie needs to be compressed as ogg.

You can easily do the conversion in unity and save it as an external file using the export to ogg command. Or you can use one of the existing commandline tools to convert.

Thanks for your help so far. I still need a bit more.

Would this script actually be attached to a GUITexture? I’ve attached it to one, but the movie does not appear to be rendering to the 2DTexture (I’m still getting the default Unity logo).

Should I be attaching this to an empty Game Object, or, what am I doing wrong here…?

Your script works on a renderer eg. a plane.
You would want to assign it to guiTexture or guiElement instead if you want it on a gui texture.

Thanks much. I’m getting so much closer.

I’ve got the video playing, but still no audio. Jesse, in your script you say:

How do I do this? Right now, I’m importing the mov file into Unity, using the Export to .ogg function, uploading the .ogg, and referencing it in the script. But no audio…?

@wadamw:
I’m rendering this test on a 2d texture as I want my movie to respect the view perspective. In contrast, by applying the movie to a guitexture it will appear as a straight on view HUD (gui being attached to the view port of the camera–so as the camera moves so will the gui). I could be wrong but I have yet to find info showing me otherwise on how to make the gui stay put.

RE: pulling video into Unity from a server does require the data format to be (.ogg). With that said, you can simply use a conversion tool on the server side (e.g. FFMPEG2THEORA) to take a .mov or .avi etc… and output a .ogg back to the Web player. Does that make sense? I’m assuming that you wanted to automate the conversion process. If not, then you can simply convert the files client-side and then post the .ogg files for faster consumption.:slight_smile:

'Hope this helps.

Jes

Thanks. That does help.

Making the movie play as a GUI texture (and thus stay put) is alright for me, and in fact it’s what I want it to do. And I can get it to play as a GUITexture…but I’m not getting sound. How are you getting the sound attached to your texture (or to my GUITexture)?

wadamw,

I was stuck on the audio issue, too, until it dawned on me that you have to place an audio Source component to the gameobject (Select your gameobject then from menu: Component>Audio>Audio Source) You should then see a Audio Source dialog box in the inspector. From this point you’ll be able to correctly reference the ‘audio’ object of the gameobject via my script. Make sense?

Jes

Yes, it does. I added the Audio Source to my GUITexture Object, and I’m not hearing anything. I know this doesn’t exactly match what you’re doing, but any idea why I wouldn’t be able to hear anything?

Hmm…are you applying the script directly to a gameobject? And then referencing the guitexture object on the gameobject for viewing? Which as you say should work for viewing. The does script assumes that it is attached to a gameobject with an audio source component. From there you should be able to simply point the audio member of the gameobject to the audioclip member of the incoming movietexture. i.e.

...
audio.clip = movieTexture.audioClip; //<--for reference

// Play both movie  sound
...
audio.Play(); //<-------------------------for the snd.

In the end, the view and the sound are separate. Let me know how that goes. There is an audio member of the guitexture itself. But it’s not clear on whether or not it also references the parent gameobject audio member so, next, we can try that approach e.g. guiTexture.audio.Play();

I figured out that the problem was that the GUITexture was too far from the camera; so it couldn’t “hear” it.

I just turned up the volume and turned down the Rolloff Factor.

I am having a little bit of an issue in the two getting off-sync. Have you had any problem with that?

Lol. I guess the audio is too smart taking into account for pan (which I love) but distance makes sense as well. :stuck_out_tongue:

Regarding the sync being off, I’ve come across it only occasionally and it’s inconsistent to reproduce. But I’ll keep a sharp eye on it and let you know.

Jes

Thanks. I’ll let you know if I find anything as well. Thanks so much for your help on this.

[/quote]

I tried this code by attaching the script to a plane.

I got the following error:
NullReferenceException:Object not set to an instance of an object.

for the line:

while (!mov.isReadyToPlay)

You are assigning the texture to the renderer instead of the GUI Texture.
Also when you assign the audio clip, you need to make sure an audio source has previously been attached to the game object,

Thanks for the feedback. I am a newbie and so please bear with me I am a little slow.

-added a cube object
-added guiTexture
-added audio component with clip
-added script from docs file://localhost/Applications/Unity/Unity.app/Contents/Documentation/Documentation/ScriptReference/WWW-movie.html

error- NullReferenceException:Object reference not set to an instance of an object.
it doesn’t like this line

while (!movieTexture.isReadyToPlay)