Fix problem with YouTube and Vimeo seeking while playing
This commit is contained in:
		@ -9,6 +9,9 @@ import utils from './../utils';
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// Set playback state and trigger change (only on actual change)
 | 
					// Set playback state and trigger change (only on actual change)
 | 
				
			||||||
function assurePlaybackState(play) {
 | 
					function assurePlaybackState(play) {
 | 
				
			||||||
 | 
					    if (play && !this.embed.hasPlayed) {
 | 
				
			||||||
 | 
					        this.embed.hasPlayed = true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    if (this.media.paused === play) {
 | 
					    if (this.media.paused === play) {
 | 
				
			||||||
        this.media.paused = !play;
 | 
					        this.media.paused = !play;
 | 
				
			||||||
        utils.dispatchEvent.call(this, this.media, play ? 'play' : 'pause');
 | 
					        utils.dispatchEvent.call(this, this.media, play ? 'play' : 'pause');
 | 
				
			||||||
@ -153,19 +156,20 @@ const vimeo = {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                // Get current paused state and volume etc
 | 
					                // Get current paused state and volume etc
 | 
				
			||||||
                const { embed, media, paused, volume } = player;
 | 
					                const { embed, media, paused, volume } = player;
 | 
				
			||||||
 | 
					                const restorePause = paused && !embed.hasPlayed;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                // Set seeking state and trigger event
 | 
					                // Set seeking state and trigger event
 | 
				
			||||||
                media.seeking = true;
 | 
					                media.seeking = true;
 | 
				
			||||||
                utils.dispatchEvent.call(player, media, 'seeking');
 | 
					                utils.dispatchEvent.call(player, media, 'seeking');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                // If paused, mute until seek is complete
 | 
					                // If paused, mute until seek is complete
 | 
				
			||||||
                Promise.resolve(paused && embed.setVolume(0))
 | 
					                Promise.resolve(restorePause && embed.setVolume(0))
 | 
				
			||||||
                    // Seek
 | 
					                    // Seek
 | 
				
			||||||
                    .then(() => embed.setCurrentTime(time))
 | 
					                    .then(() => embed.setCurrentTime(time))
 | 
				
			||||||
                    // Restore paused
 | 
					                    // Restore paused
 | 
				
			||||||
                    .then(() => paused && embed.pause())
 | 
					                    .then(() => restorePause && embed.pause())
 | 
				
			||||||
                    // Restore volume
 | 
					                    // Restore volume
 | 
				
			||||||
                    .then(() => paused && embed.setVolume(volume))
 | 
					                    .then(() => restorePause && embed.setVolume(volume))
 | 
				
			||||||
                    .catch(() => {
 | 
					                    .catch(() => {
 | 
				
			||||||
                        // Do nothing
 | 
					                        // Do nothing
 | 
				
			||||||
                    });
 | 
					                    });
 | 
				
			||||||
 | 
				
			|||||||
@ -66,6 +66,9 @@ function mapQualityUnits(levels) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// Set playback state and trigger change (only on actual change)
 | 
					// Set playback state and trigger change (only on actual change)
 | 
				
			||||||
function assurePlaybackState(play) {
 | 
					function assurePlaybackState(play) {
 | 
				
			||||||
 | 
					    if (play && !this.embed.hasPlayed) {
 | 
				
			||||||
 | 
					        this.embed.hasPlayed = true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    if (this.media.paused === play) {
 | 
					    if (this.media.paused === play) {
 | 
				
			||||||
        this.media.paused = !play;
 | 
					        this.media.paused = !play;
 | 
				
			||||||
        utils.dispatchEvent.call(this, this.media, play ? 'play' : 'pause');
 | 
					        utils.dispatchEvent.call(this, this.media, play ? 'play' : 'pause');
 | 
				
			||||||
@ -469,7 +472,7 @@ const youtube = {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                        case 1:
 | 
					                        case 1:
 | 
				
			||||||
                            // Restore paused state (YouTube starts playing on seek if the video hasn't been played yet)
 | 
					                            // Restore paused state (YouTube starts playing on seek if the video hasn't been played yet)
 | 
				
			||||||
                            if (player.media.paused) {
 | 
					                            if (player.media.paused && !player.embed.hasPlayed) {
 | 
				
			||||||
                                player.media.pause();
 | 
					                                player.media.pause();
 | 
				
			||||||
                            } else {
 | 
					                            } else {
 | 
				
			||||||
                                assurePlaybackState.call(player, true);
 | 
					                                assurePlaybackState.call(player, true);
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user