douqiang5809 2014-03-08 11:53
浏览 85
已采纳

JW Player根据已用时间执行操作

I have a video and series of comments on the video. Each comment has a specific time associated with the video. For example video 1 has 3 comments. one in second 15, another in second 30, and the last comment is in second 45.

I can show all the comments. However, instead I want each comment to be shown on its associated time of the video. For example, comment 1 should only be appeared in second 15 and lasts until second 30 where it is replaced by second comment and so on.

I'm using JW Player to play the video and can get getPosition() function to get the current elapsed time of the video. It should be a simple JavaScript code to achieve this but unfortunately I'm so beginner with JS.

My own idea to achieve this is to use onTime function and for each position check if there is a comment in the server or not, and retrieve if there is. As in:

<script>
      jwplayer("container1").onTime(
           function(event) { 
            {
               var comment = get_comment_of(event.position);
               setText(comment);
               function setText(text) {
                   document.getElementById("message").innerHTML = text;
               }

            });
</script>

However, this is an expensive function and will send huge number of requests to the server.

  • 写回答

1条回答 默认 最新

  • doufei4418 2014-03-15 16:16
    关注

    Ok, the best solution I have preloaded the comments in a javascript array when the page is loaded, then show them when they occur using onTime function. This way there is no need to send a new request on on every onTime frame. As the comments are already available on the client side

    var timeArray = <?php echo json_encode($timeArray) ?>;
    var commentArray = <?php echo json_encode($commentArray) ?>;
    jwplayer("container1").onTime(
        function(event) {
           for (var i = 0; i < timeArray.length; i++)
           {
               var time = timeArray[i]
               var comment = commentArray[i];
               if (event.position >= time) {
                   setText(comment);
               }
           }
    
    
           function setText(text) {
               document.getElementById("message").innerHTML = text;                     }
           }
    );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 vscode开发micropython,import模块出现异常
  • ¥20 Excel数据自动录入表单并提交
  • ¥30 silcavo仿真,30分钟,只需要代码
  • ¥15 FastReport 怎么实现打印后马上关闭打印预览窗口
  • ¥15 利用3支股票数据估计其均值和方差的95%置信区间。
  • ¥15 微信小程序运行一项功能时,弹出未知错误弹框,检查代码没有问题
  • ¥15 ATAC测序生成self-pseudo replicates之前是否要进行去线粒体reads
  • ¥15 python模糊字匹配函数问题
  • ¥20 谁刷目标页面的uv记录器上数据,数据只记录跳转的数值
  • ¥30 数据库软件的安装方法
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部