0
votes

How can I have a video play in a Vuforia Image target using Unity? The Vuforia core samples seem overly complicated.

1

1 Answers

1
votes

There is no need to over-complicate it. Just use a Quad, and a VideoPlayer.

  1. Create a Quad as a child of the Image target
  2. Create a VideoPlayer as child of the Quad. Be sure to set the Video Clip property to the video you want to play

The setup should look like this:

Setup

  1. Set the Renderer property of the VideoPlayer to the previously created Quad
  2. Uncheck the Play on Wake property on the VideoPlayer
  3. Use this script to Play and Stop the VideoPlayer. Place the script on the Image Target

    using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; using Vuforia;

    public class ImageTargetBehaviour : MonoBehaviour, ITrackableEventHandler { private TrackableBehaviour mTrackableBehaviour; public UnityEvent myStartEvent; public UnityEvent myStopEvent;

    void Start()
    {
        mTrackableBehaviour = GetComponent<TrackableBehaviour>();
        if (mTrackableBehaviour)
        {
            mTrackableBehaviour.RegisterTrackableEventHandler(this);
        }
    }
    
    public void OnTrackableStateChanged(
                                    TrackableBehaviour.Status previousStatus,
                                    TrackableBehaviour.Status newStatus)
    {
        if (newStatus == TrackableBehaviour.Status.DETECTED ||
            newStatus == TrackableBehaviour.Status.TRACKED ||
            newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
        {
            // When target is found
            myStartEvent.Invoke();
        }
        else
        {
            // When target is lost
            myStopEvent.Invoke();
        }
    }
    

    }

  4. Now make the VideoPlayer Start and Stop in the Component Inspector of this script

Image Target Behaviour Script