How to go back with Unity VideoPlayer and a url source?

Hello,

I’m trying to play a video from a url like this: mywebsite.com is available for purchase - Sedo.com
I can play it and use a slider to move forward in the video.

However, I can’t go back. The playback time of the VideoPlayer remains unchanged.
I would like to know if this is a normal behavior because I am using a url or if it is a problem related to the VideoPlayer?
The VideoPlayer seems to have only a way to go forward in the playback (StepForward method and canStep property to know if we can go forward) which gives me the impression that we can’t go backward, is it really impossible?

I’m currently using Unity 2019.4.2f1, I’ve been looking for answers for several days but I haven’t found anything about the use of urls. If you have links to one or more topics that deal with the same problem, I’m interested in.

Finally, I ask my last question, is there a way to go backwards in the reading of a video by url?

I’m attaching the source code that I use to launch the video and to move forward/backward with the slider.

Have a nice day,
Antonin

Source code to load the video:

    public class UIVideoPlayerContainer : UIVideoContainer
    {
        public VideoPlayer videoPlayer;
        public AudioSource audioSource;

        public GameObject videoWaiting;
        public VideoNavBar videoPlayerBar;

        float targetTime = 0;
       
        private void Start()
        {
            videoPlayer.source = VideoSource.Url;

            videoPlayer.prepareCompleted += delegate
            {
                videoWaiting.SetActive(false);
                videoPlayerBar.Enabled = true;

                videoPlayer.Play();
                videoPlayer.time = targetTime;
            };
        }

        public override IEnumerator PlayUrl(string url, float startTime = 0)
        {
            if (!url.Contains("https://") || url == "")
            {
                Debug.LogError("Bad video url:" + url);
                yield break;
            }

            videoPlayerBar.Enabled = false;
            videoWaiting.SetActive(true);

            if (videoPlayer.isPlaying || videoPlayer.isPaused)
            {
                videoPlayer.Stop();
                videoPlayer.url = "";
            }

            videoPlayer.url = url;
            videoPlayer.SetTargetAudioSource(0, audioSource);

            targetTime = startTime;
            videoPlayer.Prepare();
        }
       
        public override IEnumerator Reset()
        {
            int step = 0;

            while(step < 2)
            {
                if (step == 0)
                    videoPlayer.Stop();
                else if (step == 1)
                    base.Reset();

                step++;
               
                yield return null;
            }
        }
    }

Source code attached to the slider:

    [Serializable]
    public class NavigationSliderEvent : UnityEvent<float>
    { }

    [RequireComponent(typeof(Slider))]
    public class NavigationSlider : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
    {
        public VideoPlayer videoPlayer;

        public Slider slider;
        public NavigationSliderEvent OnSlideFinished;

        public bool slide = false;

        private void Start()
        {
            slider = GetComponent<Slider>();
        }

        private void Update()
        {
            if(!slide)
                slider.value = (float)videoPlayer.frame / videoPlayer.frameCount;
        }

        public void SetTime(float value)
        {
            videoPlayer.frame = (long)(value * videoPlayer.frameCount);
        }

        public void OnPointerDown(PointerEventData eventData)
        {
            slide = true;
            videoPlayer.Pause();
        }

        public void OnPointerUp(PointerEventData eventData)
        {
            OnSlideFinished?.Invoke(slider.value);
            slide = false;
        }
    }

I’ve tried with videoPlayer.time and videoPlayer.frame but neither of them want to go backwards.
SetTime is called using OnSlideFinished in the Unity editor.

You need to actually reset the time etc on the video player in order to play again. Just call stop:

I just tested this and it resets the time so if this does not work, you are doing something incorrect somewhere that is setting the time or keeping the time of the video player

If that doesnt work, literally enable and disable the video player object entirely. If that still does not work, instantiate a new one.

I also tried something with Stop but the video always restarted to the begining. I understood that was because targetTime was fixed to 0 every time and the delegate on prepareCompleted was called when I play the video.
Finally, I just move the SetTime method into UIVideoPlayerContainer class to be able to fix targetTime with the value.

Thanks for your help! It allowed me to see where the error was in my reasoning.
Antonin

Here’s my source code if anyone else is interested:

    public class UIVideoPlayerContainer : UIVideoContainer
    {
        public VideoPlayer videoPlayer;
        public AudioSource audioSource;

        public GameObject videoWaiting;
        public VideoNavBar videoPlayerBar;

        float targetTime = 0;
      
        private void Start()
        {
            videoPlayer.source = VideoSource.Url;

            videoPlayer.prepareCompleted += delegate
            {
                videoWaiting.SetActive(false);

                videoPlayerBar.Enabled = true;
                videoPlayerBar.SetNavigationSlider(targetTime, (float)videoPlayer.length);

                videoPlayer.Play();
                videoPlayer.time = targetTime;
            };
        }

        public override IEnumerator PlayUrl(string url, float startTime = 0)
        {
            if (!url.Contains("https://") || url == "")
            {
                Debug.LogError("Bad video url:" + url);
                yield break;
            }

            videoPlayerBar.Enabled = false;
            videoWaiting.SetActive(true);

            if (videoPlayer.isPlaying || videoPlayer.isPaused)
            {
                videoPlayer.Stop();
                videoPlayer.url = "";
            }

            videoPlayer.url = url;
            videoPlayer.SetTargetAudioSource(0, audioSource);

            targetTime = startTime;
            videoPlayer.Prepare();
        }

        public void SetTime(float value)
        {
            videoPlayer.Stop();

            targetTime = value;
            videoPlayer.Prepare();
        }

        public override IEnumerator Reset()
        {
            int step = 0;

            while(step < 2)
            {
                if (step == 0)
                    videoPlayer.Stop();
                else if (step == 1)
                    base.Reset();

                step++;
              
                yield return null;
            }
        }
    }

I use time and set the Slider max value with video length.
The SetTime method is called using OnSlideFinished of the NavigationSlider class and set in the Unity editor.