如何在HTML页面中显示Javascript / Jquery值? VideoJs显示视频的内容 [英] How to display Javascript/Jquery value in HTML page? VideoJs Display durration of the video

查看:346
本文介绍了如何在HTML页面中显示Javascript / Jquery值? VideoJs显示视频的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在使用HTML5 Jquery视频播放器。
在这里,您可以获得有关此HTML视频播放器的更多信息: http://www.videojs。 com / docs / api /

Hi there i am currently working on HTML5 Jquery video player. Here you can get more info about this HTML video player: http://www.videojs.com/docs/api/

从这个链接中你可以看到 myPlayer.duration()是必须以秒为单位显示视频的功能。这就是我只想在简单的HTML页面中显示这个值,就像我正在尝试使用我的代码一样。

From this link you can see that myPlayer.duration() is the function that must show the video durration in seconds. And that's it i just want to display this value in simple HTML page like i am trying with my code.

这是我的代码:

 <head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
</head>
  <video id="vemvo-player" class="video-js vjs-default-skin" controls autoplay="true" width="950" height="534"
      data-setup="{}">
    <source src="[var.base_url]/uploads/[var.video_play]" type='video/flv' />
  </video>
<div id="duration"></div>
<script type="text/javascript">
        var myPlayer = _V_("vemvo-player");
    _V_("vemvo-player").ready(function(){
        var howLongIsThis = myPlayer.duration();
        $('#duration').html('Duration: ' + howLongIsThis);
    });
</script>

此代码的问题在于它显示持续时间:0 当视频持续时间远离0时。

The problem with this code is that it's showing Duration: 0 when the video duration is far from 0.

我的视频播放器工作正常,它正确显示视频的嗡嗡声。
我的问题是如何在HTML页面值中显示这种情况?

My video player is working okey and it's showing durration of the video correctly. My question is how i can show this durration in HTML page value?

当我发布 var myPlayer = _V_时使用上面的代码(vemvo-player); 进入 _V _(vemvo-player)。ready(function(){函数,我尝试进入控制台运行 myPlayer.duration()它给我一个未定义变量的错误,但是当 var myPlayer = _V _(vemvo-player); 在函数之外,就像它在我的帖子中一样,我在控制台中键入 myPlayer.duration(),它让我在几秒钟内就像我需要的那样匆匆忙忙它。

With the code above when i post var myPlayer = _V_("vemvo-player"); into _V_("vemvo-player").ready(function(){ function and i try in the console to run myPlayer.duration() it gives me error for Undefined variable, but when var myPlayer = _V_("vemvo-player"); is outside the function like it is in my post and i type myPlayer.duration() in the console it's giving me the durration in seconds like i need it.

问题是我可以将这个变量显示为HTML页面中的数字。
我只是想在HTML页面中显示这个数字。

The problem is that i can display this variable as a number in HTML page. I just want to display this number in HTML page.

我的代码中的错误在哪里以及如何解决?

Where is the mistake in my code and how i can fix it?

提前致谢!

推荐答案

<script type="text/javascript">
var myPlayer = _V_("vemvo-player");
_V_("vemvo-player").ready(function(){
   // Any ready/init code you want here
   $('#duration').html('Duration: ');        
});
myPlayer.addEventListener('loadedmetadata', function() {
    $('#duration').html('Duration: ' + myPlayer.duration);
});
</script>

来源

这篇关于如何在HTML页面中显示Javascript / Jquery值? VideoJs显示视频的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆