mediaelement.js - Prevent Seek Forward / Allow Seek Backwards

只愿长相守 提交于 2019-12-08 09:16:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!