Ziggeo SDK视频播放器 - 获取搜索时间[关闭]

问题描述 投票:0回答:1

在任何Ziggeo的SDK中, 你能看出这个播放器的第二个视频吗?

我想知道观众何时进入视频30秒(例如)。

似乎有方法(事件),如播放,暂停,寻找;但是,如果其中任何一个都能返回用户所在视频中的值,则不明显。

我可以通过观看播放和暂停事件来推断它们的位置,但是搜索会转到视频中不可预测的部分

api video sdk ziggeo-sdk
1个回答
0
投票

正如您所说,有几个事件可用于此类实现,我将假设您将使用v2(因为这是推荐的方式)。

事件是:

  1. 播放
  2. 暂停
  3. 结束
  4. 寻求

playing事件将在3个案例中被激活:

  1. 视频播放开始了
  2. 视频暂停后激活播放操作
  3. 搜索选项用于达到视频中的特定点,seek事件被触发,然后播放也将触发(因为视频现在再次播放)。

paused事件将在2个案例中被激活:

  1. 当有人点击暂停按钮时
  2. 在最后,暂停事件火灾,然后是ended事件。

endedseek事件仅在特定案例出现时才会触发(分别使用视频或搜索结束)。

然而,seek事件有一个传递给函数的参数--position允许我们快速获得搜索操作发生的确切时间。

  • 了解这一点,我们知道会发生什么,什么时候会发生。

获取数据(任何视频数据)的方法是使用embedding.get();。按原样使用它将返回一个有用细节的整个对象,但是对于位置,您只需键入“position”。

这是可行的事件代码:

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);
});
  • 你可以看到抓住'position'和'totalduration',这只是为了举例。
  • 最好指出seek事件在position参数中获取正确的数据,因此使用它而不是.get()方法,因为它可以告诉你一个稍微“较旧”的值。

以下是完整的代码段,但您需要添加自己的应用程序令牌和视频令牌。要做到这一点,只需将“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>

我在代码中添加了链接的注释,希望能提供更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.