Exemple #1
0
    // Change the video player state to seeking.
    public override void OnPointerDown(PointerEventData ptrData)
    {
        base.OnPointerDown(ptrData);

        // User has to watch the complete video before seeking becomes avaliable.
        if (!timeLine.interactable)
        {
            return;
        }

        prevState     = console.State;
        console.State = EVideoState.seeking;
    }
    // Check the state of the video player state machine.
    void FixedUpdate()
    {
        //debugTimeText.text = videoPlayer.time.ToString();
        //debugFrameText.text = videoPlayer.frame.ToString();

        // Sets the proper state once the video has stopped.
        if (videoPlayer.time >= videoPlayer.clip.length)
        {
            State = EVideoState.stopped;
        }

        // State machine
        switch (state)
        {
        case EVideoState.stopped: {
            // User has watched the video fully when this state is triggered.

            if (triggerOnce.Trigger())
            {
                break;
            }

            pauseFilter.SetActive(true);
            btnText.text      = ">";
            videoPlayer.frame = 0;
            videoPlayer.StepForward();

            timeLine.interactable = true;

            timeText.text =
                FormatTime((int)videoPlayer.time) + " / " + FormatTime((int)videoPlayer.clip.length);
            timeLine.value = (float)videoPlayer.time / (float)videoPlayer.clip.length;

            break;
        }

        case EVideoState.paused: {
            if (triggerOnce.Trigger())
            {
                break;
            }

            videoPlayer.Pause();
            pauseFilter.SetActive(true);
            btnText.text = ">";

            break;
        }

        case EVideoState.playing: {
            if (triggerOnce.Trigger())
            {
                videoPlayer.Play();
                pauseFilter.SetActive(false);
                btnText.text = "ll";
            }

            if (videoPlayer.isPlaying)
            {
                timeText.text =
                    FormatTime((int)videoPlayer.time) + " / " + FormatTime((int)videoPlayer.clip.length);
                timeLine.value = (float)videoPlayer.time / (float)videoPlayer.clip.length;
            }

            break;
        }

        case EVideoState.seeking: {
            if (triggerOnce.Trigger())
            {
                videoPlayer.Pause();
                pauseFilter.SetActive(false);
            }

            double sliderTime = (timeLine.value * (float)videoPlayer.clip.length);

            timeText.text =
                FormatTime((int)sliderTime) + " / " + FormatTime((int)videoPlayer.clip.length);

            // TODO:
            // Update renderer.

            // NOTE:
            // As of 2017-07-24, there is not an effective way to seek and update
            // to a current frame in the API. The only way to render a frame
            // is to call Play() or StepForward(), which the latter would just
            // cause the video to basically play without sound in this loop.
            //
            // This seek state works as intended, however the visual frame will
            // not update until the user is done seeking.

            break;
        }
        }
    }