- Home /
Audio delay after loading ogg external movie at runtime
Hi, after i load an ogg video as a MovieTexture everything works exept that the audio has a delay of some frames and when is done to load i hear a "bleep" before the movie start. It looks like the audio and the video are not sync. In the code i disable the video and audio components at start and re-enabled them after everything is loaded but the audio "bleep" still there... do you have any idea? Thanks in advacne, here is the code:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.IO;
[RequireComponent(typeof(RawImage))]
[RequireComponent(typeof(AudioSource))]
public class LoadFilesController : MonoBehaviour {
string path = "C:/Video/";
string url = "file:///C:/Video/";
string fileName = "ff7.ogg";
string[] files;
RawImage player;
AudioSource sound;
MovieTexture movie;
void Start () {
player = GetComponent<RawImage> ();
sound = GetComponent<AudioSource> ();
files = Directory.GetFiles (path);
foreach (string file in files){
Debug.Log(file);
}
StartCoroutine (loadMovie ());
}
IEnumerator loadMovie(){
player.enabled = false;
sound.enabled = false;
WWW www = new WWW (url + fileName);
yield return www;
if (www.error != null) {
Debug.Log ("Error: Can't laod movie! - " + www.error);
yield break;
} else {
MovieTexture video = www.movie as MovieTexture;
Debug.Log("Movie loaded");
Debug.Log(video.duration);
movie = video;
player.texture = movie;
sound.clip = movie.audioClip;
sound.Stop ();
playMovie();
}
}
public void playMovie(){
if (movie.isReadyToPlay) {
Debug.Log ("movie can start");
movie.Stop ();
sound.Stop ();
player.enabled = true;
sound.enabled = true;
movie.Play ();
sound.Play ();
}
}
public void pauseMovie(){
movie.Pause ();
sound.Pause ();
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Unity 5 how to load movie (movieTexture) from local folder in Win 2 Answers
How to get the "real" key value (position, rotation, scale) of object after applying layer weight 1 Answer
Refresh panel with prefab contained value from json that created using array 0 Answers