1

我深入研究了 Ooyala Player JS API,搜索当当前正在播放的视频达到其长度的 75% 时将触发的事件。

Ooyala 提供了一种方法来查询某个视频有多少 0%、25%、50%、75% 和 100% 的观看次数,但我找不到做我想做的事的方法。

我已经在http://support.ooyala.com/developers/documentation/concepts/book_api_player.html检查了所有内容

以前有人经历过吗?您知道其他可以提供帮助的信息来源吗?

提前致谢。

4

3 回答 3

4
var videoPlayer = OO.Player.create('Player', embedcode, {
    autoplay: true,
    onCreate: function (player) {
        mesb = player.mb;
    }    
});

mesb.subscribe(OO.EVENTS.PLAYBACK_READY, 'example', _.bind(this.videoPlaying, this));
mesb.subscribe(OO.EVENTS.PLAYHEAD_TIME_CHANGED, 'example', _.bind(this.playheadTime, this));
function videoPlaying() {
    var title, desc, embed, dur;
    var vData = videoPlayer.getItem();
    dur = vData.time;

}

function playheadTime() {
    phPos = videoPlayer.getPlayheadTime();
    if (phPos > 90) {
        alert('you are 90 seconds in to the video!');
    }

dur会给你视频的总时间。 phPos会给你当前的播放头时间。

您应该能够进行数学运算,并在达到一定百分比后让视频触发动作。在我的示例中,当视频达到 90 秒时,我设置了一个警报。

于 2013-01-02T22:43:02.243 回答
2
I think this will work
var videoPlayer = OO.Player.create('Player', embedcode, {
    autoplay: true,
    onCreate: function (player) {
        mesb = player.mb;
    }    
});

mesb.subscribe(OO.EVENTS.PLAYBACK_READY, 'example', _.bind(this.videoPlaying, this));
mesb.subscribe(OO.EVENTS.PLAYHEAD_TIME_CHANGED, 'example', _.bind(this.playheadTime, this));
function videoPlaying() {
    var title, desc, embed, dur;
    var vData = videoPlayer.getItem();
    dur = vData.time;

}

function playheadTime() {
    if((videoPlayer.getPlayheadTime())>= (videoPlayer.getDuration()*0.25)){ 
      alert('play 25%') 
    }
    if((videoPlayer.getPlayheadTime())>= (videoPlayer.getDuration()*0.50)){ 
      alert('play 50%') 
    }
    if((videoPlayer.getPlayheadTime())>= (videoPlayer.getDuration()*0.75)){ 
      alert('play 75%') 
    }
    if((videoPlayer.getPlayheadTime())>= (videoPlayer.getDuration()*1.00)){ 
      alert('play 100%') 
    }
}
于 2014-05-21T06:27:15.630 回答
2

早期答案中提供的代码对我有帮助,但需要一些修改。需要将其包装在 中OO.ready,并进行修改以使代码准确调用 4 次:完成 25%、50%、75% 和 100%。

var mplayer, mesb, dur, title;
OO.ready(function() {
  var lastTriggerPos;
  mplayer = OO.Player.create('ooyalaplayer', embedcode);
  mplayer.mb.subscribe(OO.EVENTS.PLAYBACK_READY, 'example', function(eventName) {
    title = mplayer.getCurrentItemTitle();
    var vData = mplayer.getItem();
    dur = parseInt(vData.time);
  });
  mplayer.mb.subscribe(OO.EVENTS.PLAYHEAD_TIME_CHANGED, 'example', function(eventName) {
    phPos = parseInt(mplayer.getPlayheadTime());
    if ((phPos == parseInt(dur * 0.25)) && phPos != lastTriggerPos) {
      lastTriggerPos = phPos;
      alert('25%');
    }
    if ((phPos == parseInt(dur * 0.50)) && phPos != lastTriggerPos) {
      lastTriggerPos = phPos;
      alert('50%');
    }
    if ((phPos == parseInt(dur * 0.75)) && phPos != lastTriggerPos) {
      lastTriggerPos = phPos;
      alert('75%');
    }
    if ((phPos == parseInt(dur * 1)) && phPos != lastTriggerPos) {
      lastTriggerPos = phPos;
      alert('100%');
    }
  });
});
于 2015-09-11T08:26:01.510 回答