- Home /
video texture plays too fast when adding audio
I have a video texture on a primitive cube; attached to that is a PlayMovie-Script with the functions play and stop. The player can play and stop the movie with a mousedownbutton. Everything went well, all the scripts work and the video plays whenever i want to.
But when I added the corresponding audioclip to the gameobject (imported with the video of course), something strange happened: the whole video plays with sound, but suddenly at 4 times the speed than it should be. This is the line of code where I start video & audio:
function Play () { renderer.material.mainTexture.Play(); Debug.Log("played movie!"); audio.Play(); PlayerCollisions.moviePlays = true; }
If I disable //audio.Play(); the speed is back to normal.
Ideas, anyone?
Answer by atsakir · Sep 28, 2012 at 01:50 PM
For all those that share this problem, the issue appears when .play() is called more than once either on video or audio. Make sure you call `.play()` inside an `if (!video.isPlaying)` statement. Here is a script for playing either video or audio with delay and/or via trigger showing how this is done correctly:
 #pragma strict
 
 var delay : float = 0.0;
 private var timer : float;
 private var video : MovieTexture;
 private var isPlaying : boolean = false;
 var MovieObject : GameObject = null;
 private var obj_audio : AudioSource;
 var play_on_trigger : boolean = false;
 private var play : boolean = false;
 var loop : boolean = false;
 
 function Start () {
     timer = delay;   
     if (MovieObject == null) MovieObject = gameObject;
     if (MovieObject!=null)    { 
         if (MovieObject.renderer) 
         {
             video = MovieObject.renderer.material.mainTexture as MovieTexture;    
         }
         obj_audio = MovieObject.GetComponent(AudioSource);
         if (obj_audio != null) {
         }
     }
     if (!play_on_trigger) 
         play = true;
     if (loop && video) {
         video.loop = true;
     }
 }
 
 function Update () {
     if (MovieObject != null && play) {
         if (timer < 0) {
             if ( MovieObject.renderer) 
                 MovieObject.renderer.enabled = true;
             if (video && !video.isPlaying) {
                 video.Play();
             }
             if (obj_audio && !obj_audio.isPlaying) {
                 obj_audio.Play();
             }
             else Debug.Log(MovieObject.name+" no audio");
             isPlaying = true;
         }
         timer -= Time.deltaTime;
     }
 
 }
 
 function OnTriggerEnter()
 {
     play = true;
 }
 
Answer by LeeGibson · Jul 01, 2011 at 02:31 PM
seems like it may have been a bug - rebuild the scene, did exactly the same as before, and now it works as it should.
just in case anybody else encounters the problem ;)
Your answer
 
 
             Follow this Question
Related Questions
Changing texture when movie is paused 0 Answers
Video texture problem? 2 Answers
GST Movie Texture - How to mute video?? 0 Answers
Add a Movie Texture to UI Button 0 Answers
playing audio from a video clip 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                