Skip to content

Commit

Permalink
fix: reset to a play/pause button when seeking after ended (#4614)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey authored and gkatsev committed Sep 20, 2017
1 parent d8ea23e commit 335bcde
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/js/control-bar/play-toggle.js
Expand Up @@ -57,6 +57,26 @@ class PlayToggle extends Button {
}
}

/**
* This gets called once after the video has ended and the user seeks so that
* we can change the replay button back to a play button.
*
* @param {EventTarget~Event} [event]
* The event that caused this function to run.
*
* @listens Player#seeked
*/
handleSeeked(event) {
// remove the ended class
this.removeClass('vjs-ended');

if (this.player_.paused()) {
this.handlePause(event);
} else {
this.handlePlay(event);
}
}

/**
* Add the vjs-playing class to the element so it can change appearance.
*
Expand All @@ -66,7 +86,6 @@ class PlayToggle extends Button {
* @listens Player#play
*/
handlePlay(event) {
this.removeClass('vjs-ended');
this.removeClass('vjs-paused');
this.addClass('vjs-playing');
// change the button text to "Pause"
Expand All @@ -91,12 +110,19 @@ class PlayToggle extends Button {
/**
* Add the vjs-ended class to the element so it can change appearance
*
* @param {EventTarget~Event} [event]
* The event that caused this function to run.
*
* @listens Player#ended
*/
handleEnded(event) {
this.removeClass('vjs-playing');
this.addClass('vjs-ended');
// change the button text to "Replay"
this.controlText('Replay');

// on the next seek remove the replay button
this.one(this.player_, 'seeked', this.handleSeeked);
}
}

Expand Down

0 comments on commit 335bcde

Please sign in to comment.