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

Youtube provider doesn't seekTo nor play #44

Closed dy closed 3 years ago

dy commented 3 years ago
const player = new Vlitejs('#player',{
  options: {
    playPause: false,
    time: false,
    volume: false,
    fullscreen: false,
    poster: false,
    // loop: true,
    // providerParams: {start: 1, end: 2, loop: 1}
  },
  provider: 'youtube',
  onReady: async (player) => {
    player.seekTo(1)
    player.play()
  }
});

just hangs with the error:

base.js:371 Uncaught 
g.pE {errorCode: "onesie.unavailable.hotconfig", i: false, details: {…}}
details: {url: "0"}
errorCode: "onesie.unavailable.hotconfig"
i: false

neither seekTo(x) nor play() work

dy commented 3 years ago

Side question: why all events are conventionally handled via player.on(event, handler), whereas onReady requires a separate option? Why can't it just be player = new vlitejs(...); player.on('ready', handler)?

dy commented 3 years ago

Hey @yoriiis I like your player, it's nice looking good alternative, would like to use it in a little coming project (charity). If you'd consider making these little fixes to bring it to polished state, I can make a donation.

dy commented 3 years ago

@yoriiis any hope for response?

yoriiis commented 3 years ago

neither seekTo(x) nor play() work

@dy The autoplay policy is strict and can only be initiated by a user gesture. But, if the video is muted, the play is granted. The autoplay parameter does it automatically (muted + play) and it works.

If you want to do some code before the play (seek or something else), you can use the onReady function. The muted needs to be enabled. There is a bug to transfer the mute option to the player, I will make a fix. You can still use the methods directly:

const player = new Vlitejs('#player', {
    options: {
        playPause: false,
        time: false,
        volume: false,
        fullscreen: false,
        poster: false
        // muted: true To be fixed
    },
    provider: 'youtube',
    onReady: async (player) => {
        player.seekTo(10)
        player.mute()
        player.play()
    }
})

Side question: why all events are conventionally handled via player.on(event, handler), whereas onReady requires a separate option? Why can't it just be player = new vlitejs(...); player.on('ready', handler)?

When I wrote it, I preferred to separate the "onReady" function.


Hey @yoriiis I like your player, it's nice looking good alternative, would like to use it in a little coming project (charity). If you'd consider making these little fixes to bring it to polished state, I can make a donation.

Great, share your project when you're ready. Thanks for sponsoring me :)

yoriiis commented 3 years ago

This has been fixed and merged in main. Release 4.0.2 is available ! 🎉