vlite icon indicating copy to clipboard operation
vlite copied to clipboard

seekTo autoplays youtube video

Open squareclouds opened this issue 1 year ago • 4 comments

Describe the bug

this happens only for youtube. if i use the seekTo function the video autoplays after going to that second.

Steps to reproduce

  • dont autoplay the video
  • call the seekTo function via a button click (currently i am going to second 0)

Expected behavior

video should jump to the second but not autoplay, if the video was in paused state

Screenshots and recordings

No response

Vlite.js

4.0.6

Browser

latest firefox and chrome

OS

macos 12.5

Additional context

No response

squareclouds avatar Aug 07 '22 09:08 squareclouds

just to be more detailed, i am trying to reset the current video via events.

as a workaround i am doing this:

async reset() {
        // bug in youtube if the video was not playing already
        let time = await this.player.player.getCurrentTime();
        
        if(time > 0){
            this.player.player.pause();
            this.player.player.seekTo(0);
        } 
    }
now youtube videos are not getting messed up, but again, it is strange that only youtube has behaving like this.

squareclouds avatar Aug 07 '22 10:08 squareclouds

Hello @squareclouds, could you please share a small reproducible repository? In my tests, your code works.

yoriiis avatar Aug 07 '22 21:08 yoriiis

@yoriiis i will try to recreate it in a simple way this week, my use case is quite complex at this point

squareclouds avatar Aug 09 '22 06:08 squareclouds

Hello @squareclouds, could you please share a small reproducible repository? In my tests, your code works.

hi yoriiis... i am wondering, what did you mean by "my code is working"? again, the code i posted works, yes, because i first check if the video is already at 0, and only if it is not the case i jump to 0. but the original problem i found was, that if you dont check if it is already at 0 and you just jump anyway, the player shows the behaviour i mentioned at the beginning. please let me know if there was a misunderstanding.

here i created a jsfiddle:

https://jsfiddle.net/squareclouds/2x6q1u8g/37/

after the video is loaded i seekTo 0 and vimeo (and html5 as well) dont do anything, as expected, but youtube starts to play.

squareclouds avatar Aug 09 '22 12:08 squareclouds

This is native behavior with Youtube, it will play the video after the seekTo call if it is not started yet. If the state is different (playing, paused) it does not change. I will keep this behavior even if it is different on other provider. But, if the video is not muted, the browser blocks the playback according to the autoplay policy.

So, I added a fix on the Youtube provider to mute the video in this case only. See PR above.

yoriiis avatar Aug 11 '22 13:08 yoriiis