问题
Can you please give me an idea or sample that I can prevent seek forward to the seeking bar but will allow to seek backwards?
This is what I found but it keeps on a loop:
media.addEventListener('seeked', function(e) {
// player.setCurrentTime(0);
// player.play();
}, true);
回答1:
What i did was this: Inside the uncompressed version of mediaelement library find a row: media.setCurrentTime(newTime);
Add above the previous line: if ( newTime <= media.currentTime )
Eventually you have:
if ( newTime <= media.currentTime )
media.setCurrentTime(newTime);
which means that if the time to be seeked is lower or equal to the player's current time then allow seeking.
回答2:
I recently had the same requirement.
But didn't really want to modify the source file.
Here's another way of doing it without modifying the source:
var _player = $("#my_video_1")[0].player; //<-- get the reference to the player
old = _player.media.setCurrentTime; //<-- store the native setCurrentTime temporarily
_player.media.setCurrentTime = function(time) { //<-- override it with our own method
if(time <= this.currentTime){
old.apply(this,[time]); //<-- call the stored method if our conditions are met
}
};
来源:https://stackoverflow.com/questions/14958190/mediaelement-js-prevent-seek-forward-allow-seek-backwards