Ooyala Player Event - 当玩家到达视频的某个点时发出通知

时间:2012-07-03 03:50:27

标签: javascript api ooyala

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

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

我已经检查了http://support.ooyala.com/developers/documentation/concepts/book_api_player.html

的所有内容

以前有人经历过这个吗? 您是否知道其他任何可能有用的信息来源?

提前致谢。

2 个答案:

答案 0 :(得分: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秒时,我会设置一个警报设置。

答案 1 :(得分: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%') 
    }
}