Log in or register to post comments

Video Playback - Play automatically

September 7, 2012 - 6:34am #1

Hi,

Is there an easy solution to making the video play automatically when its triggered, and not having to press the Play Icon?

I have tried modifying the VideoPlayBackController Update() method, but im not sure what to change inside of the VideoPlaybackBehaviour script.

 

Adam

Video Playback - Play automatically

February 4, 2013 - 3:29am #15

Awesome - glad to hear it!

Though please be aware that in the video playback sample, the correct Trackable Event Handletr is already added by default, otherwise the sample would not work :)

N

Video Playback - Play automatically

February 1, 2013 - 7:02am #14

 

Yes It worked!
 
 
 
As per your suggestion, the component has to be attached on the ImageTarget, however since the one included by default in the example is Default Trackable Event Handler, it has to be deleted and then the component (script) Trackable event handler has to be added, comment the lines and presto!
 
Many Thanks! :-)

Video Playback - Play automatically

February 1, 2013 - 6:39am #13

 

My Man,
 
 
 
Its not there. Check it out:
 
 
 
 
 
 
What's included is the "default Trackable Evnet Handler" which is doesn't contain any playback instructions at all.
 
Thanks.

Video Playback - Play automatically

February 1, 2013 - 6:28am #12

Forum gremlins have eaten my pictures :(

Follow the steps I described and it should be fine :)

N

Video Playback - Play automatically

February 1, 2013 - 6:20am #11

I can't see the picture. It will be very nice :-P

 

Thanks!

Video Playback - Play automatically

February 1, 2013 - 6:15am #10

"Trackable event handler" its not included by default

Incorrect.  It is included by default in the video playback sample - hence the picture I posted for you.

1  Load up the video playback sample

2  Click on the image target and there you will find it already attached to the image target in the inspector

N

Video Playback - Play automatically

February 1, 2013 - 6:01am #9

Hello NalinS,

 

I know "Trackable event handler" its not included by default, I'm using it because it is being suggested in this thread. And as I said before: I did already tried commenting the lines out on what are you seuggesting, the thing is, to which entity I attach the component?

 

Many Thanks.

Video Playback - Play automatically

February 1, 2013 - 2:40am #8

"Trackable event handler" script its not included by default on the example.

It is included by default.

When I load up the video playback sample and click on the Image Target and look in inspector, I see the script as shown below

 

Regarding the AutoPlay, if you open up the TrackableEventHandler script then you should find the code that will enable this commented out.  If you uncomment this then the videos will auto play.

HTH

N

 

 

        // Optionally play the video automatically when the target is found

        

        VideoPlaybackBehaviour video = GetComponentInChildren<VideoPlaybackBehaviour>();

        if (video != null)

        {

            if (video.VideoPlayer.IsPlayableOnTexture())

            {

                VideoPlayerHelper.MediaState state = video.VideoPlayer.GetStatus();

                if (state == VideoPlayerHelper.MediaState.PAUSED ||

                    state == VideoPlayerHelper.MediaState.READY ||

                    state == VideoPlayerHelper.MediaState.STOPPED)

                {

                    // Pause other videos before playing this one

                    PauseOtherVideos(video);

 

                    // Play this video on texture where it left off

                    video.VideoPlayer.Play(false, video.VideoPlayer.GetCurrentPosition());

                }

                else if (state == VideoPlayerHelper.MediaState.REACHED_END)

                {

                    // Pause other videos before playing this one

                    PauseOtherVideos(video);

 

                    // Play this video from the beginning

                    video.VideoPlayer.Play(false, 0);

                }

            }

        }

 

 

 

Video Playback - Play automatically

January 31, 2013 - 1:17pm #7

Ok,

 

Lets just put it straight: I have the very simple requirement of playing the video as soon as the image is tracked. As suggested below I tried with the "Trackable event handler" but I'm lost there.

 

Veryfying the included scripts on the Video triggers example (for Unity of course) I found within the script VideoPlayerHelper.cs the following lines:

 

bool videoPlayerLoad(string filename, int requestType, bool playOnTextureImmediately, float seekPosition) { return false; }
 
bool videoPlayerIsPlayableOnTexture() { return false; }
 
I changed both to:
 
bool videoPlayerLoad(string filename, int requestType, bool playOnTextureImmediately, float seekPosition) { return true; }
 
bool videoPlayerIsPlayableOnTexture() { return true; }
 
 

However, behaviour is the same (meaning no autoplay). Am I on the right track? What should I change on the included video example so I have Autoplayback of the video when triggered by the image.

 
Many Thanks.

 

Video Playback - Play automatically

January 31, 2013 - 11:38am #6

Hello NalinS,

 

Thanks for your reply.

 

Your suggestion is exactly what I did, however "Trackable event handler" script its not included by default on the example. It has to be added, hence my original question:

 

To which entity I add the component (script in this case): Trackable event handler

 

Many Thanks!

Video Playback - Play automatically

January 31, 2013 - 8:50am #5

hi llanero,

The best thing to do is to create a new project and import the video playback sample package.

Once you have this you can see what is connected to what and then you can try to get auto playback to work.

Then you should be in a good place.

N

Video Playback - Play automatically

January 31, 2013 - 8:44am #4

Hello People,

 

Pardon my ignorance, but:

 

1) To which entity I attach the script? Is it to the ARCamera? ImageTarget? Or to the "Video" within the ImageTarget?

2) To enable the automatic play, I just take out the comment on the script and that's it?

 

I have tried several iterations, however I've not been succesfull.

 

Thanks for your help.

Video Playback - Play automatically

September 10, 2012 - 7:52am #3

Brilliant thanks.

Feel stupid for not seeing this, didnt think to check this file, thought it was a default AR one, no custom for Video Playback!

Video Playback - Play automatically

September 7, 2012 - 9:20am #2

Here is a Trackable event handler script that supports autoplay.

 

using UnityEngine;

// A custom handler that implements the ITrackableEventHandler interface.
public class TrackableEventHandler : MonoBehaviour,
                                     ITrackableEventHandler
{
    #region PRIVATE_MEMBER_VARIABLES

    private TrackableBehaviour mTrackableBehaviour;

    private bool mHasBeenFound = false;
    private bool mLostTracking;
    private float mSecondsSinceLost;

    #endregion // PRIVATE_MEMBER_VARIABLES

    #region UNITY_MONOBEHAVIOUR_METHODS

    void Start()
    {
        mTrackableBehaviour = GetComponent<TrackableBehaviour>();
        if (mTrackableBehaviour)
        {
            mTrackableBehaviour.RegisterTrackableEventHandler(this);
        }

        OnTrackingLost();
    }

    void Update()
    {
        // Pause the video if tracking is lost for more than two seconds
        if (mHasBeenFound && mLostTracking)
        {
            if (mSecondsSinceLost > 2.0f)
            {
                VideoPlaybackBehaviour video = GetComponentInChildren<VideoPlaybackBehaviour>();
                if (video != null &&
                    video.CurrentState == VideoPlayerHelper.MediaState.PLAYING)
                {
                    video.VideoPlayer.Pause();
                }

                mLostTracking = false;
            }

            mSecondsSinceLost += Time.deltaTime;
        }
    }

    #endregion // UNITY_MONOBEHAVIOUR_METHODS

    #region PUBLIC_METHODS

    // Implementation of the ITrackableEventHandler function called when the
    // tracking state changes.
    public void OnTrackableStateChanged(
                                    TrackableBehaviour.Status previousStatus,
                                    TrackableBehaviour.Status newStatus)
    {
        if (newStatus == TrackableBehaviour.Status.DETECTED ||
            newStatus == TrackableBehaviour.Status.TRACKED)
        {
            OnTrackingFound();
        }
        else
        {
            OnTrackingLost();
        }
    }

    #endregion // PUBLIC_METHODS

    #region PRIVATE_METHODS

    private void OnTrackingFound()
    {
        Renderer[] rendererComponents = GetComponentsInChildren<Renderer>();
        Collider[] colliderComponents = GetComponentsInChildren<Collider>();

        // Enable rendering:
        foreach (Renderer component in rendererComponents)
        {
            component.enabled = true;
        }

        // Enable colliders:
        foreach (Collider component in colliderComponents)
        {
            component.enabled = true;
        }

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

        // Optionally play the video automatically when the target is found
        /*
        VideoPlaybackBehaviour video = GetComponentInChildren<VideoPlaybackBehaviour>();
        if (video != null)
        {
            if (video.VideoPlayer.IsPlayableOnTexture())
            {
                VideoPlayerHelper.MediaState state = video.VideoPlayer.GetStatus();
                if (state == VideoPlayerHelper.MediaState.PAUSED ||
                    state == VideoPlayerHelper.MediaState.READY ||
                    state == VideoPlayerHelper.MediaState.STOPPED)
                {
                    // Pause other videos before playing this one
                    PauseOtherVideos(video);

                    // Play this video on texture where it left off
                    video.VideoPlayer.Play(false, video.VideoPlayer.GetCurrentPosition());
                }
                else if (state == VideoPlayerHelper.MediaState.REACHED_END)
                {
                    // Pause other videos before playing this one
                    PauseOtherVideos(video);

                    // Play this video from the beginning
                    video.VideoPlayer.Play(false, 0);
                }
            }
        }
        */

        mHasBeenFound = true;
        mLostTracking = false;
    }

    private void OnTrackingLost()
    {
        Renderer[] rendererComponents = GetComponentsInChildren<Renderer>();
        Collider[] colliderComponents = GetComponentsInChildren<Collider>();

        // Disable rendering:
        foreach (Renderer component in rendererComponents)
        {
            component.enabled = false;
        }

        // Disable colliders:
        foreach (Collider component in colliderComponents)
        {
            component.enabled = false;
        }

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

        mLostTracking = true;
        mSecondsSinceLost = 0;
       
       
    }

    // Pause all videos except this one
    private void PauseOtherVideos(VideoPlaybackBehaviour currentVideo)
    {
        VideoPlaybackBehaviour[] videos = (VideoPlaybackBehaviour[])
                FindObjectsOfType(typeof(VideoPlaybackBehaviour));

        foreach (VideoPlaybackBehaviour video in videos)
        {
            if (video != currentVideo)
            {
                if (video.CurrentState == VideoPlayerHelper.MediaState.PLAYING)
                {
                    video.VideoPlayer.Pause();
                }
            }
        }
    }

    #endregion // PRIVATE_METHODS
}

Log in or register to post comments