vlitejs / vlite

🦋 vLitejs is a fast and lightweight Javascript library for customizing video and audio player in Javascript with a minimalist theme (HTML5, Youtube, Vimeo, Dailymotion)
https://vlite.js.org
MIT License
268 stars 18 forks source link

seekTo autoplays youtube video #74

Closed squareclouds closed 2 years ago

squareclouds commented 2 years ago

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

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 commented 2 years ago

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.
yoriiis commented 2 years ago

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

squareclouds commented 2 years ago

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

squareclouds commented 2 years ago

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.

yoriiis commented 2 years ago

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.