videojs:操纵SeekBar的起始值(总是0),以支持类似DVR / DVR的流式传输

时间:2015-09-23 15:45:12

标签: live video.js seekbar dvr

我希望使用videojs实现类似http://www.dash-player.com/demo/live-streaming-dvr/的类似内容。

我从wowza流引擎获得了manifest.mpd(type = dynamic),并将 timeShiftBufferDepth 设置为15分钟。 我使用videojs v4.12.15,dashjs v1.5.0和videojs-contrib-dash v1.1.1来显示流。

如您所见,SeekHandle位于位置0. currentTime位于216:07:07(来自manifest.mpd),持续时间为4.99 ...巨大。 (videojs接缝有无限的问题,但这在这里并不重要)

当视频继续时,SeekHandle停留在位置0,因为持续时间(数量巨大)太高,无法到达。 videojs接缝以持续时间的百分比推进SeekHandle。当我将持续时间设置为currentTime时,

player.on("timeupdate", function () {
   this.duration(this.currentTime());
});

SeekHandle出现在最后。

当我现在尝试在SeekBar中搜索时,SeekBar包含从00:00:00到持续时间值的值(currentTime == 216:07:07)。至于流的性质,我无法回到流的开头,但多亏了dvr,我可以回到15分钟。

这意味着,我希望能够从currentTime-15min(215:52:07)到currentTime(216:07:07)寻求。要实现这一点,我必须改变SeekBar的起始值,这正是我迷失的地方。我不知道如何改变它从00:00:00到currentTime-15min(215:52:07)

tl; dr如何在init或更高版本中更改videojs SeekBar的起始值?

1 个答案:

答案 0 :(得分:0)

我的解决方案,如果有人有类似的问题:

您必须在原始videojs脚本中编辑或修改以下功能:

vjs.SeekBar.prototype.onMouseMove = function(event){
  var newTime = this.calculateDistance(event) * this.player_.duration();

  // Don't let video end while scrubbing.
  if (newTime == this.player_.duration()) { newTime = newTime - 0.1; }

  // Set new time (tell player to seek to new time)
  this.player_.currentTime(newTime);
};

this.calculateDistance(event)返回0到1之间的值,该值描述了您在SeekBar上的点击位置。因此,如果您在SeekBar中间完全点击,将返回0.5。

可以说,你想要一个50秒的滑动窗口,然后你必须改变newTime的分配。

var newTime = (this.player_.currentTime() - 50) + (this.calculateDistance(event) * 50);

实施例: 你想在视频中返回25秒。为此,您可以在其中间单击SeekBar。该事件被触发,this.calculateDistance(event)设置为0.5。 0.5 * 50正好是25秒。 (this.player_.currentTime() - 50)定义了SeekBar的开始(0%)。添加计算的25秒将为您提供所需的时间。

您可以在此处查看我的插件:https://gist.github.com/bernhardreisenberger/da0ff4e9a30aa4b6696e 这只是一个原型,并没有完成插件。 SeekHandle仍处于错误的位置和其他问题。