在任何Ziggeo的SDK中,
你能看出该播放器的第二个视频吗?
我想知道观众何时进入视频30秒(例如)。
似乎有像玩,暂停,寻找等方法(事件);但是,如果其中任何一个都能返回用户所在视频中的值,那么这一点并不明显。
我可以通过观看播放和暂停活动来推断它们的位置,但是搜索会转到视频中不可预测的部分
答案 0 :(得分:0)
正如你所说,有几个事件可用于此类实现,我将假设您将使用v2(因为这是推荐的方式)。
事件是:
playing
事件将在3种情况下被激活:
seek
事件已触发,然后播放也将触发(因为视频现在再次播放)。 paused
事件将在2种情况下被激活:
ended
事件。 ended
和seek
事件仅在特定案例出现时触发(分别使用视频或搜索结尾)。
seek
事件有一个传递给函数的参数 - position
,允许我们快速获得搜索操作发生的确切时间。
获取数据(任何视频数据)的方法是使用embedding.get();
。按原样使用它将返回整个有用细节的对象,但是对于位置,您只需键入“位置”。
这是可行的事件代码:
player.on('playing', function(){
console.log('This is "playing" event from ' + player.get('position') + ' of ' + player.get('totalduration') );
});
player.on('paused', function(){
console.log('This is "paused" event at ' + player.get('position') + ' of ' + player.get('totalduration') );
});
player.on('ended', function(){
console.log('This is "ended" event at ' + player.get('position') + ' of ' + player.get('totalduration') );
});
player.on('seek', function(position){
console.log('This is "seek" event at ' + player.get('position') + ' of ' + player.get('totalduration') );
console.log('quicker way and more reliable:' + position);
});
以下是完整的代码段,但您需要添加自己的应用令牌和视频令牌。 要做到这一点,只需将“APP_TOKEN”替换为您的应用程序令牌,将“VIDEO_TOKEN”替换为视频令牌或密钥。
<!DOCTYPE html>
<html>
<head>
<!-- We are declaring our resource calls at this location -->
<link rel="stylesheet" href="https://assets-cdn.ziggeo.com/v2-stable/ziggeo.css" />
<script src="https://assets-cdn.ziggeo.com/v2-stable/ziggeo.js"></script>
<script>
var ziggeoapp = new ZiggeoApi.V2.Application({
token:"APP_TOKEN",
webrtc_streaming: true
});
ZiggeoApi.V2.Locale.setLocale("en");
// the above can be quickly retrieved from https://ziggeo.com/docs/sdks/javascript/browser-integration/header
//utilizing application event. This makes sure that the code is checked for after DOMReady and Ziggeo system is initialized.
//application events: https://ziggeo.com/docs/sdks/javascript/browser-interaction/application-events
ziggeoapp.on('ready', function() {
var player = new ZiggeoApi.V2.Player({
element: document.getElementById('player_placeholder'),
attrs: {
countdown: 3,
width: 640,
height: 480,
theme: 'modern',
themecolor: 'red',
video: 'VIDEO_TOKEN'
}
});
player.activate();
//if we want to listed to all embeddings on the page, regardless of knowing which it is, we could use the application wide embedding events approach (global events system): https://ziggeo.com/docs/sdks/javascript/browser-interaction/application-embedding-events
//however the private events seem much better for reacting to them
//https://ziggeo.com/docs/sdks/javascript/browser-interaction/events
player.on('playing', function(){
console.log('This is "playing" event from ' + player.get('position') + ' of ' + player.get('totalduration') );
});
player.on('paused', function(){
console.log('This is "paused" event at ' + player.get('position') + ' of ' + player.get('totalduration') );
});
player.on('ended', function(){
console.log('This is "ended" event at ' + player.get('position') + ' of ' + player.get('totalduration') );
});
player.on('seek', function(position){
console.log('This is "seek" event at ' + player.get('position') + ' of ' + player.get('totalduration') );
console.log('quicker way and more reliable:' + position);
});
});
</script>
</head>
<body>
<div id="player_placeholder"></div>
</body>
</html>
我在代码中添加了带有链接的注释,希望能提供更多信息。