Log in or register to post comments

How to reset seek position to zero

June 12, 2013 - 5:17am #1

Hi Guys,

I am running VideoPlayBack sample app. i want to restart the video every time it detects the trackable image. How can i do that ?

 

Thanks  

How to reset seek position to zero

December 19, 2018 - 1:37am #3

I also want to ask the same question. Below is my script. I want user to seek the video forward or rewind. Where to put the code?

 

 

 

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

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

Vuforia is a trademark of PTC Inc., registered in the United States and other

countries.

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

using UnityEngine;

using UnityEngine.Video;

using UnityEngine.UI;

[RequireComponent(typeof(VideoPlayer))]

public class VideoController : MonoBehaviour

{

    #region PRIVATE_MEMBERS

    private VideoPlayer videoPlayer;

    #endregion //PRIVATE_MEMBERS



    #region PUBLIC_MEMBERS

    public Button m_PlayButton;

    public RectTransform m_ProgressBar;

    #endregion //PRIVATE_MEMBERS



    #region MONOBEHAVIOUR_METHODS

    void Start()

    {

        videoPlayer = GetComponent<VideoPlayer>();

        // Setup Delegates

        videoPlayer.errorReceived += HandleVideoError;

        videoPlayer.started += HandleStartedEvent;

        videoPlayer.prepareCompleted += HandlePrepareCompleted;

        videoPlayer.seekCompleted += HandleSeekCompleted;

        videoPlayer.loopPointReached += HandleLoopPointReached;

        LogClipInfo();

    }

    void Update()

    {

        if (videoPlayer.isPlaying)

        {

            ShowPlayButton(false);

            video.play(false);

            if (videoPlayer.frameCount < float.MaxValue)

            {

                float frame = (float)videoPlayer.frame;

                float count = (float)videoPlayer.frameCount;

                float progressPercentage = 0;

                if (count > 0)

                    progressPercentage = (frame / count) * 100.0f;

                if (m_ProgressBar != null)

                    m_ProgressBar.sizeDelta = new Vector2((float)progressPercentage, m_ProgressBar.sizeDelta.y);

            }

        }

        else

        {

            ShowPlayButton(true);

        }

    }

    void OnApplicationPause(bool pause)

    {

        Debug.Log("OnApplicationPause(" + pause + ") called.");

        if (pause)

            Pause();

    }

    #endregion // MONOBEHAVIOUR_METHODS



    #region PUBLIC_METHODS

    public void Play()

    {

        Debug.Log("Play Video");

        PauseAudio(false);

        videoPlayer.Play();

        ShowPlayButton(false);

    }

    public void Pause()

    {

        if (videoPlayer)

        {

            Debug.Log("Pause Video");

            PauseAudio(true);

            videoPlayer.Pause();

            ShowPlayButton(true);

        }

    }

    #endregion // PUBLIC_METHODS



    #region PRIVATE_METHODS

    private void PauseAudio(bool pause)

    {

        for (ushort trackNumber = 0; trackNumber < videoPlayer.audioTrackCount; ++trackNumber)

        {

            if (pause)

                videoPlayer.GetTargetAudioSource(trackNumber).Pause();

            else

                videoPlayer.GetTargetAudioSource(trackNumber).UnPause();

        }

    }

    private void ShowPlayButton(bool enable)

    {

        m_PlayButton.enabled = enable;

        m_PlayButton.GetComponent<Image>().enabled = enable;

    }

    private void LogClipInfo()

    {

        if (videoPlayer.clip != null)

        {

            string stats =

                "\nName: " + videoPlayer.clip.name +

                "\nAudioTracks: " + videoPlayer.clip.audioTrackCount +

                "\nFrames: " + videoPlayer.clip.frameCount +

                "\nFPS: " + videoPlayer.clip.frameRate +

                "\nHeight: " + videoPlayer.clip.height +

                "\nWidth: " + videoPlayer.clip.width +

                "\nLength: " + videoPlayer.clip.length +

                "\nPath: " + videoPlayer.clip.originalPath;

            Debug.Log(stats);

        }

    }

    #endregion // PRIVATE_METHODS



    #region DELEGATES

    void HandleVideoError(VideoPlayer video, string errorMsg)

    {

        Debug.LogError("Error: " + video.clip.name + "\nError Message: " + errorMsg);

    }

    void HandleStartedEvent(VideoPlayer video)

    {

        Debug.Log("Started: " + video.clip.name);

    }

    void HandlePrepareCompleted(VideoPlayer video)

    {

        Debug.Log("Prepare Completed: " + video.clip.name);

    }

    void HandleSeekCompleted(VideoPlayer video)

    {

        Debug.Log("Seek Completed: " + video.clip.name);

    }

    void HandleLoopPointReached(VideoPlayer video)

    {

        Debug.Log("Loop Point Reached: " + video.clip.name);

        ShowPlayButton(true);

    }

    #endregion //DELEGATES

}

How to reset seek position to zero

June 12, 2013 - 5:28am #2

Hi, 

you may want to have a look at this article:

https://developer.vuforia.com/forum/faq/android-how-can-i-update-my-ui-response-tracking-events

which explains how to perform a custom action in response to a trackable being detected.

You can then use it as a starting point to achieve your functionality, i.e. restarting the video upon trackable detection.

Note that how to restart / play /pause the video is shown in the VideoPlayback sample, so you can find all the necessary code in there, and in particular I suggest to have a look at the VideoPlayerHelper class (in VideoPlayerHelper.java), which contains all the core business logic to handle the video.

 

Log in or register to post comments