To ensure a movie is prepared before it's played by subscribing to a prepareCompleted event, do the following:
- Add a UI RawImage to the scene by going to GameObject | UI | Raw Image.
- Create a new, empty GameObject named video-object.
- Create a C# script class named PrepareCompleted and attach an instance of the script as a component to the video-object GameObject:
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
public class PrepareCompleted: MonoBehaviour {
public RawImage image;
public VideoClip videoClip;
private VideoPlayer videoPlayer;
private AudioSource audioSource;
void Start() {
SetupVideoAudioPlayers();
videoPlayer.prepareCompleted += PlayVideoWhenPrepared;
videoPlayer.Prepare();
Debug.Log("A - PREPARING");
}
private void SetupVideoAudioPlayers() {
videoPlayer = gameObject.AddComponent<VideoPlayer>();
audioSource = gameObject.AddComponent...