sampotts / plyr

A simple HTML5, YouTube and Vimeo player
https://plyr.io
MIT License
26.51k stars 2.93k forks source link

Youtube video currentTime modification does not update progress bar #1979

Open btamas opened 4 years ago

btamas commented 4 years ago

Expected behaviour

If currentTime setter is called when provider is youtube, progress bar should be updated, even the video is paused.

Actual behaviour

Progress bar will be updated only when the video will be started again.

Steps to reproduce

Environment

Browser: Chrome 85.0.4183.121, Safari 14.0, Firefox 81.0.2 Operating System: MacOS Version: 10.15.7

Console errors (if any)

Link to where the bug is happening

https://codepen.io/btamax/pen/OJXyeRp

MacMaru commented 3 years ago

related: #1848

Not limited to Youtube, also on HTML5 and Vimeo. Bit different for Vimeo: there's no seek to the requested time: nothing happens.

jeff-hykin commented 3 years ago

I found this as a decent work-around. The setTimeout section seems to be necessary for it to work.

Object.defineProperty(Object.getPrototypeOf(this.player), "currentTime", {
    set(input) {
        // Bail if media duration isn't available yet
        if (!this.duration) { return }
        // Validate input
        input = input-0
        const inputIsValid = (input == input) && input >= 0
        if (inputIsValid) {
            // Set
            this.media.currentTime = Math.min(input, this.duration)
            let location = (input / this.duration) * 100
            setTimeout(() => {
                this.elements.inputs.seek.setAttribute("value", location)
                this.elements.inputs.seek.setAttribute("aria-valuenow", location)
                this.elements.inputs.seek.style.setProperty("--value", `${location}%`)
            }, 0)
        }
        // Logging
        this.debug.log(`Seeking to ${this.currentTime} seconds`)
    }
})
limonte commented 3 years ago

Thanks for the workaround @jeff-hykin

dy commented 3 years ago

That's nice workaround, why not incorporating it? I can confirm this bug:


const player = new Plyr('#youtube-player', {
  controls: ['play', 'progress'],
  fullscreen: {enabled: false},
  youtube: {noCookie: true, showinfo: 0, controls: 0},
});

player.on('ready', () => {
  player.currentTime = 0.1
})

doesn't update progress.