x


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?

more ▼

asked Jun 20 '11 at 03:16 PM

LeeGibson gravatar image

LeeGibson
51 8 9 10

(comments are locked)
10|3000 characters needed characters left

2 answers: sort newest

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;
}
more ▼

answered Sep 28 '12 at 01:50 PM

atsakir gravatar image

atsakir
1 1

(comments are locked)
10|3000 characters needed characters left

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 ;)

more ▼

answered Jul 01 '11 at 02:31 PM

LeeGibson gravatar image

LeeGibson
51 8 9 10

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2188
x1024
x355
x280
x224

asked: Jun 20 '11 at 03:16 PM

Seen: 1118 times

Last Updated: Sep 28 '12 at 01:50 PM