Skip to content

Commit

Permalink
Detect when seek has been called by user interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
TronchDeYack committed Sep 21, 2021
1 parent 6474890 commit c5b6856
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
11 changes: 7 additions & 4 deletions build/mediaelement-and-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1620,7 +1620,7 @@ Object.assign(_player2.default.prototype, {
}

setTimeout(function () {
player.setCurrentTime(newTime);
player.setCurrentTime(newTime, true);
}, 0);

setTimeout(function () {
Expand Down Expand Up @@ -1650,7 +1650,7 @@ Object.assign(_player2.default.prototype, {
}

setTimeout(function () {
player.setCurrentTime(newTime);
player.setCurrentTime(newTime, true);
}, 0);

setTimeout(function () {
Expand Down Expand Up @@ -1817,7 +1817,7 @@ Object.assign(_player2.default.prototype, {
},
handleMouseup = function handleMouseup() {
if (mouseIsDown && t.getCurrentTime() !== null && t.newTime.toFixed(4) !== t.getCurrentTime().toFixed(4)) {
t.setCurrentTime(t.newTime);
t.setCurrentTime(t.newTime, true);
t.setCurrentRailHandle(t.newTime);
t.updateCurrent(t.newTime);
}
Expand Down Expand Up @@ -1907,7 +1907,7 @@ Object.assign(_player2.default.prototype, {
}

setTimeout(function () {
t.setCurrentTime(seekTime);
t.setCurrentTime(seekTime, true);
}, 0);

if (seekTime < t.getDuration() && !startedPaused) {
Expand Down Expand Up @@ -5083,6 +5083,9 @@ var MediaElementPlayer = function () {
}, {
key: 'setCurrentTime',
value: function setCurrentTime(time) {
var userInteraction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

this.seekUserInteraction = userInteraction;
this.proxy.setCurrentTime(time);
}
}, {
Expand Down
2 changes: 1 addition & 1 deletion build/mediaelement-and-player.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ readyState | Return the current ready state of the audio/video | X |
seeking | Return whether the user is currently seeking in the audio/video | X |
src | Set or return the current source of the audio/video element | X | X
volume | Set or return the volume of the audio/video | X | X
seekUserInteraction | Return true when the seek has been called by a user interaction | X | X

<a id="methods"></a>
### Methods
Expand All @@ -186,7 +187,7 @@ canPlayType(type) | Determine whether current player can/cannot play a specific
setPlayerSize (width, height) | Set player's `width` and `height` also considering the `stretching` configuration
setPoster (url) | Add a `image` tag with the poster's `url` inside the player's layer; you can pass an _empty_ string to clear the poster
setMuted (muted) | Mute/unmute the player; `muted` is a boolean value
setCurrentTime (time) | Set a new current time for the player; `time` is either an integer or float number, and if negative, it will start from zero.
setCurrentTime (time, userInteraction) | Set a new current time for the player; `time` is either an integer or float number, and if negative, it will start from zero.
getCurrentTime () | Retrieve the current time of the media being played
setVolume (volume) | Set a volume level for the player; `volume` is a number between `0` and `1`
getVolume () | Retrieve the current volume level of the media being played
Expand Down
8 changes: 4 additions & 4 deletions src/js/features/progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Object.assign(MediaElementPlayer.prototype, {

// make sure time is updated after 'pause' event is processed
setTimeout(function() {
player.setCurrentTime(newTime);
player.setCurrentTime(newTime, true);
}, 0);

// start again to track new time
Expand Down Expand Up @@ -139,7 +139,7 @@ Object.assign(MediaElementPlayer.prototype, {

// make sure time is updated after 'pause' event is processed
setTimeout(function() {
player.setCurrentTime(newTime);
player.setCurrentTime(newTime, true);
}, 0);

// start again to track new time
Expand Down Expand Up @@ -337,7 +337,7 @@ Object.assign(MediaElementPlayer.prototype, {
},
handleMouseup = () => {
if (mouseIsDown && t.getCurrentTime() !== null && t.newTime.toFixed(4) !== t.getCurrentTime().toFixed(4)) {
t.setCurrentTime(t.newTime);
t.setCurrentTime(t.newTime, true);
t.setCurrentRailHandle(t.newTime);
t.updateCurrent(t.newTime);
}
Expand Down Expand Up @@ -434,7 +434,7 @@ Object.assign(MediaElementPlayer.prototype, {

// make sure time is updated after 'pause' event is processed
setTimeout(function() {
t.setCurrentTime(seekTime);
t.setCurrentTime(seekTime, true);
}, 0);

if (seekTime < t.getDuration() && !startedPaused) {
Expand Down
3 changes: 2 additions & 1 deletion src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1815,7 +1815,8 @@ class MediaElementPlayer {
return this.proxy.load();
}

setCurrentTime (time) {
setCurrentTime (time, userInteraction = false) {
this.seekUserInteraction = userInteraction;
this.proxy.setCurrentTime(time);
}

Expand Down

0 comments on commit c5b6856

Please sign in to comment.