Log in or register to post comments

Video will not play when Play On Awake is unchecked

May 8, 2020 - 10:22pm #1

Hello all, 

 

I am very new to both Unity and Vuforia but I am just trying to make a simple app where image target is Tracked and a video plays. I also want the video to only play when it's tracked and pause when it's not (which I was also able to successfully do, but it has broken somehow).

I was able to successfully make this for both iOS and Android, but I went in to tweak and add some things without creating a new scene just in case. 

Now something has gone wrong and I don't know what!

 

The issue is that when the Play On Awake button is unchecked, my video no longer plays and I just get a blank quad. When Play on Awake is checked, the video plays normally. 

 

See screenshots attached. 

 

See code from DefaultTrackableEvent below. It seems like some new things have been added into this code but I have no idea how or why or what. Any advice is appreciated! I have the mobile app version on both Android and iOS that still work as intended.

 

 

==============================================================================

using UnityEngine;

using UnityEngine.Events;

using Vuforia;

/// <summary>

/// A custom handler that implements the ITrackableEventHandler interface.

///

/// Changes made to this file could be overwritten when upgrading the Vuforia version.

/// When implementing custom event handler behavior, consider inheriting from this class instead.

/// </summary>

public class DefaultTrackableEventHandler : MonoBehaviour

{

    public enum TrackingStatusFilter

    {

        Tracked,

        Tracked_ExtendedTracked,

        Tracked_ExtendedTracked_Limited

    }

    /// <summary>

    /// A filter that can be set to either:

    /// - Only consider a target if it's in view (TRACKED)

    /// - Also consider the target if's outside of the view, but the environment is tracked (EXTENDED_TRACKED)

    /// - Even consider the target if tracking is in LIMITED mode, e.g. the environment is just 3dof tracked.

    /// </summary>

    public TrackingStatusFilter StatusFilter = TrackingStatusFilter.Tracked_ExtendedTracked_Limited;

    public UnityEvent OnTargetFound;

    public UnityEvent OnTargetLost;



    protected TrackableBehaviour mTrackableBehaviour;

    protected TrackableBehaviour.Status m_PreviousStatus;

    protected TrackableBehaviour.Status m_NewStatus;

    protected bool m_CallbackReceivedOnce = false;

    protected virtual void Start()

    {

        mTrackableBehaviour = GetComponent<TrackableBehaviour>();

        if (mTrackableBehaviour)

        {

            mTrackableBehaviour.RegisterOnTrackableStatusChanged(OnTrackableStatusChanged);

        }

    }

    protected virtual void OnDestroy()

    {

        if (mTrackableBehaviour)

        {

            mTrackableBehaviour.UnregisterOnTrackableStatusChanged(OnTrackableStatusChanged);

        }

    }

    void OnTrackableStatusChanged(TrackableBehaviour.StatusChangeResult statusChangeResult)

    {

        m_PreviousStatus = statusChangeResult.PreviousStatus;

        m_NewStatus = statusChangeResult.NewStatus;

        Debug.LogFormat("Trackable {0} {1} -- {2}",

            mTrackableBehaviour.TrackableName,

            mTrackableBehaviour.CurrentStatus,

            mTrackableBehaviour.CurrentStatusInfo);

        HandleTrackableStatusChanged();

    }

    protected virtual void HandleTrackableStatusChanged()

    {

        if (!ShouldBeRendered(m_PreviousStatus) &&

            ShouldBeRendered(m_NewStatus))

        {

            OnTrackingFound();

        }

        else if (ShouldBeRendered(m_PreviousStatus) &&

                 !ShouldBeRendered(m_NewStatus))

        {

            OnTrackingLost();

        }

        else

        {

            if (!m_CallbackReceivedOnce && !ShouldBeRendered(m_NewStatus))

            {

                // This is the first time we are receiving this callback, and the target is not visible yet.

                // --> Hide the augmentation.

                OnTrackingLost();

            }

        }

        m_CallbackReceivedOnce = true;

    }

    protected bool ShouldBeRendered(TrackableBehaviour.Status status)

    {

        if (status == TrackableBehaviour.Status.DETECTED ||

            status == TrackableBehaviour.Status.TRACKED)

        {

            // always render the augmentation when status is DETECTED or TRACKED, regardless of filter

            return true;

        }

        if (StatusFilter == TrackingStatusFilter.Tracked_ExtendedTracked)

        {

            if (status == TrackableBehaviour.Status.EXTENDED_TRACKED)

            {

                // also return true if the target is extended tracked

                return true;

            }

        }

        if (StatusFilter == TrackingStatusFilter.Tracked_ExtendedTracked_Limited)

        {

            if (status == TrackableBehaviour.Status.EXTENDED_TRACKED ||

                status == TrackableBehaviour.Status.LIMITED)

            {

                // in this mode, render the augmentation even if the target's tracking status is LIMITED.

                // this is mainly recommended for Anchors.

                return true;

            }

        }

        return false;

    }

    protected virtual void OnTrackingFound()

    {

        if (mTrackableBehaviour)

        {

            var rendererComponents = mTrackableBehaviour.GetComponentsInChildren<Renderer>(true);

            var colliderComponents = mTrackableBehaviour.GetComponentsInChildren<Collider>(true);

            var canvasComponents = mTrackableBehaviour.GetComponentsInChildren<Canvas>(true);

            // Enable rendering:

            foreach (var component in rendererComponents)

                component.enabled = true;

            // Enable colliders:

            foreach (var component in colliderComponents)

                component.enabled = true;

            // Enable canvas':

            foreach (var component in canvasComponents)

                component.enabled = true;

        }

        if (OnTargetFound != null)

            OnTargetFound.Invoke();

    }

    protected virtual void OnTrackingLost()

    {

        if (mTrackableBehaviour)

        {

            var rendererComponents = mTrackableBehaviour.GetComponentsInChildren<Renderer>(true);

            var colliderComponents = mTrackableBehaviour.GetComponentsInChildren<Collider>(true);

            var canvasComponents = mTrackableBehaviour.GetComponentsInChildren<Canvas>(true);

            // Disable rendering:

            foreach (var component in rendererComponents)

                component.enabled = false;

            // Disable colliders:

            foreach (var component in colliderComponents)

                component.enabled = false;

            // Disable canvas':

            foreach (var component in canvasComponents)

                component.enabled = false;

        }

        if (OnTargetLost != null)

            OnTargetLost.Invoke();

    }

}

AttachmentSize
Image icon Default Trackable Event97.25 KB
Image icon Play on Awake47.37 KB

Video will not play when Play On Awake is unchecked

May 12, 2020 - 4:54am #3

Hi.

Play on Awake means that the video is playing as soon as the scene has started. The trigger for the video to start is the loading of the scene.

If the video is not playing when this is unchecked, this means that its not triggering.

Could you please provide more info on videoplayer.play() and pause()?

Thank you.

Vuforia Engine Support

Video will not play when Play On Awake is unchecked

May 9, 2020 - 7:28am #2

Also I'm on Unity 2019.3.12f1 and Vuforia 9.1.7.

 

I haven't changed the versions of either between the working version and broken version. 

Log in or register to post comments