Hi i am having problems with videos in Unity. I am using a Raw Image to display and play my video, however Unity is not playing the first few seconds of my video and therefore my audio is out of sync. Does anyone have a workaround for this?
My code is below if this helps:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
[RequireComponent (typeof(AudioSource))]
public class PlayVideo : MonoBehaviour {
public MovieTexture movie2;
private AudioSource movie2audio;
void Start () {
GetComponent<RawImage>().texture = movie2 as MovieTexture;
movie2audio = GetComponent<AudioSource>();
movie2audio.clip = movie2.audioClip;
movie2.Play();
movie2audio.Play();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && movie2.isPlaying)
{
movie2.Pause();
}
else if (Input.GetKeyDown(KeyCode.Space) && !movie2.isPlaying)
{
movie2.Play();
}
}
}