- Home /
Poor, overly complicated way to do something; i.e. bad question that shouldn't have been asked.
Play MP4 on UI? (Unity 3D 2018.2)
What I have been trying to do is play instructional GIFs on my game's UI, and they show up at certain points in the tutorial (i.e. become active). I have a Video Player in the scene, and a RawImage on the canvas. The gifs are actually MP4 videos, but they are not playing, they are stuck on frame 1.
This is the script attached to the Video Player, which I got from this YouTube tutorial:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
public class GIFPlayer : MonoBehaviour {
public RawImage rawImage;
public VideoPlayer activeVideoPlayer;
// Use this for initialization
void Start () {
StartCoroutine(PlayVideo());
}
// Use this for the main functionality
IEnumerator PlayVideo()
{
activeVideoPlayer.Prepare(); //initiates playback engine preparation
WaitForSeconds waitForSeconds = new WaitForSeconds(1); //0.5f
while(!activeVideoPlayer.isPlaying)
{
yield return waitForSeconds;
break;
}
rawImage.texture = activeVideoPlayer.texture;
activeVideoPlayer.Play();
}
}
In the Inspector, the RawImages are all unchecked (since they are not supposed to immediately appear). In the Inspector settings for the Video Players, they are marked Play On Awake, Wait for First Frame, and Loop. All videos are stuck on frame 1 though, and I followed the tutorial exactly.
I've never used Video Player for UI before, so I must be missing something. Any ideas?
you're yielding while not playing and you can play after that loop that does it. the player will never start this way
Okay, now I get it. What would I write to get it to play and loop at the end?