Log in or register to post comments

Video plays automatically

March 12, 2018 - 7:47am #1

Hi all.

I'm using Unity 2017.3.1f1 and vuforia.

 

I could show 3D model and video using video player.

But it seems when I play the scene,the video plays automatically.

I wanted to play video at the same time  I found the marker.

(I mean at the same time to show 3D model)

 

I roughly know it is because I checked "Play on Awake" but when I unchecked it , I couldn't play video anymore.

Do I need a custom C# script to control video play?

 

I'll attach the config.

 

 

 

 

AttachmentSize
Image icon screenshot.300.jpg293.65 KB

Video plays automatically

May 13, 2019 - 3:06pm #7

Figured it.  change Pause to Stop.  Thanks again.

Video plays automatically

May 13, 2019 - 1:24pm #6

Thank  you so much... this is what i have been searching for.  one other question... I there any way to reset the video play when tracking is lost?

Video plays automatically

January 28, 2019 - 6:27pm #5

This really helped!! Thank you so much!!

Video plays automatically

March 18, 2018 - 5:12pm #4

Dear dpizzle 

 

Thank you for your suggestion.(and sorry for late reply)

I could do what I wanted to do.

 

I unchecked "Play On Awake" and edited 「DefaultTrackableEventHandler」 in the ImageTarget.

I could do when I find the marker then video plays and when marker loose then video pause(stop).

 

I attach my script below.

 

/*==============================================================================

Copyright (c) 2017 PTC Inc. All Rights Reserved.

Copyright (c) 2010-2014 Qualcomm Connected Experiences, Inc.

All Rights Reserved.

Confidential and Proprietary - Protected under copyright and other laws.

==============================================================================*/

using UnityEngine;

using Vuforia;

using UnityEngine.Video;      //added

/// <summary>

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

/// </summary>

public class DefaultTrackableEventHandler : MonoBehaviour, ITrackableEventHandler

{

    #region PRIVATE_MEMBER_VARIABLES

    protected TrackableBehaviour mTrackableBehaviour;

    #endregion // PRIVATE_MEMBER_VARIABLES

    #region UNTIY_MONOBEHAVIOUR_METHODS

    protected virtual void Start()

    {

        mTrackableBehaviour = GetComponent<TrackableBehaviour>();

        if (mTrackableBehaviour)

            mTrackableBehaviour.RegisterTrackableEventHandler(this);

    }

    #endregion // UNTIY_MONOBEHAVIOUR_METHODS

    #region PUBLIC_METHODS

    /// <summary>

    ///     Implementation of the ITrackableEventHandler function called when the

    ///     tracking state changes.

    /// </summary>

    public void OnTrackableStateChanged(

        TrackableBehaviour.Status previousStatus,

        TrackableBehaviour.Status newStatus)

    {

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

            newStatus == TrackableBehaviour.Status.TRACKED ||

            newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)

        {

            Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");

            OnTrackingFound();

        }

        else if (previousStatus == TrackableBehaviour.Status.TRACKED &&

                 newStatus == TrackableBehaviour.Status.NOT_FOUND)

        {

            Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");

            OnTrackingLost();

        }

        else

        {

            // For combo of previousStatus=UNKNOWN + newStatus=UNKNOWN|NOT_FOUND

            // Vuforia is starting, but tracking has not been lost or found yet

            // Call OnTrackingLost() to hide the augmentations

            OnTrackingLost();

        }

    }

    #endregion // PUBLIC_METHODS

    #region PRIVATE_METHODS

    protected virtual void OnTrackingFound()

    {

        var rendererComponents = GetComponentsInChildren<Renderer>(true);

        var colliderComponents = GetComponentsInChildren<Collider>(true);

        var canvasComponents = GetComponentsInChildren<Canvas>(true);

        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;

        // added

        if (mTrackableBehaviour.gameObject.GetComponentInChildren<VideoPlayer>() != null)

        {

            mTrackableBehaviour.gameObject.GetComponentInChildren<VideoPlayer>().Play();

        }


    }



    protected virtual void OnTrackingLost()

    {

        var rendererComponents = GetComponentsInChildren<Renderer>(true);

        var colliderComponents = GetComponentsInChildren<Collider>(true);

        var canvasComponents = 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;

        // added

        if (mTrackableBehaviour.gameObject.GetComponentInChildren<VideoPlayer>() != null)

        {

            mTrackableBehaviour.gameObject.GetComponentInChildren<VideoPlayer>().Pause();

        }

    }

    #endregion // PRIVATE_METHODS

}

 

 

Video plays automatically

March 18, 2018 - 7:12am #3

dpizzle , Thank you for your quick reply!!

(and sorry for late reply)

 

I checked the 「DefaultTrackableEventHandler」 and I tried some custom script  but it doesn't work well.

Actually I'm not familiar with #C and Unity...

what I want to do is below.2 and 3 are not done yet.

 

1. find target marker and display 3Dmodel  (this is OK . just using web cam I can find and display 3D model)

2. when I found the marker , I want to play video automatically.

3. when I lost the marker , I want to pause or stop video automatically.

 

■Question

Q1. In this case , how can I custom the script?

Do I need to create and attach new custom script to the Image Target or the Video Player's component?

(This time I use "Quad" 3D object and attach Video Player)

Or do I need to customize 「DefaultTrackableEventHandler」?

 

At the moment , just the easiest sample is OK.

if Anyone has the easiest sample or know the sample URL please tell me.

 

Thanks.

 

 

Video plays automatically

March 12, 2018 - 8:07am #2

Yes you need some custom scripting.  Check out OnTrackingFound in DefaultTrackableEventHandler.  Uncheck play on awake, and in that method do something like: GameObject.Find("SomeGameObject").GetComponent<VideoPlayer>().Play();

Log in or register to post comments