I'm trying to Play a video on canvas using the script play video on canvas in an AR app using Vuforia.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
public class StreamVideo : MonoBehaviour
{
public RawImage rawImage;
public VideoPlayer videoPlayer;
public AudioSource audioSource;
// Use this for initialization
void Start()
{
StartCoroutine(PlayVideo());
}
IEnumerator PlayVideo()
{
videoPlayer.Prepare();
WaitForSeconds waitForSeconds = new WaitForSeconds(1);
while (!videoPlayer.isPrepared)
{
yield return waitForSeconds;
break;
}
rawImage.texture = videoPlayer.texture;
videoPlayer.Play();
audioSource.Play();
}
}
and this plays video when the play button is pressed. Now I hooked this game object to Default trackable event handler so when tracking is found rawimage.gameobject.setactive(true);
and (false) when tracking is lost. The main problem here is when I show the camera in front of image target, only a Raw image is being shown and its child Videoplayer is not starting. Which results in Video Not being played. Any fix for this?
GameObject
, add the components:MeshRenderer
,MeshFilter
andVideoClip
. TheVideoClip
should now useMaterial Override
using the MeshRenderer. Now for theMeshFilter
chooseQuad
and set its size through the transform Scale (careful it is still in meters). Now create aMaterial
and add it to theMeshRenderer
(Materials -> element 0). Now you should have a Video plane that plays onAwake you can enable/disable asGameObject
– Besteadno personal data
policy but you could upload it somewhere and post a link here – BesteadMeshRenderer
->Materials
->element 0
. Just generate a new Material and drag it in there – BesteadCanvas
settings do you haveScreen Space - Overlay
orScreen Space - Camera
selected? The way I did it appears to only work withScreen Space - Overlay
but not withScreen Space Camera
– BesteadScreen Space - Camera
works for me. Otherwise it might get placed so far way from the camera that it is further than theClipping Planes
->Far
value of the camera ... maybe it also works for you just increasing this value – BesteadAssets/VideoExample/Examples
). You can see there a bit clearer what theScreenSpace - Overlay
does ... it might be better to just switch toScreenSpace - Camera
in general – Bestead