使用播放和暂停视频

Using Play and Pause video

本文关键字:暂停 视频 播放      更新时间:2023-09-26

希望你能帮助我。我有一个按钮播放和其他暂停,但不工作。谢谢。这是我的代码示例:

<!DOCTYPE html>
<html>
<head>
    <title>Video.js | HTML5 Video Player</title>
    <link href="http://vjs.zencdn.net/3.2/video-js.css" rel="stylesheet" type="text/css">
    <script src="http://vjs.zencdn.net/3.2/video.js"></script>
    <script>
        _V_.options.flash.swf = "video-js.swf";
    </script>
    <script>    
        _V_("example_video_1").ready(function(){   
            var myPlayer = this;
        }); 
    </script>
</head>
<body>
    <video id="example_video_1" class="video-js vjs-default-skin" controls preload="auto" width="640" height="264" poster="http://video-js.zencoder.com/oceans-clip.png" data-setup="{}">
        <source src="http://video-js.zencoder.com/oceans-clip.mp4" type='video/mp4' />
        <source src="http://video-js.zencoder.com/oceans-clip.webm" type='video/webm' />
        <source src="http://video-js.zencoder.com/oceans-clip.ogv" type='video/ogg' />
    </video>
    <input type="button" value="Pause" onClick="myPlayer.pause();">
    <input type="button" value="Play" onClick="myPlayer.play();">
</body>
</html>

视频设置必须在文档加载后进行。因此,您必须将其包含在"onload"函数中。如果你使用jQuery,你可以把它放在$(document).ready()中。否则你可以用window.onload。此外,你必须删除"var"关键字,因为在函数内部它创建了一个局部变量,你不能从外部访问。

那么设置脚本将变成:

<script>  
    window.onload = function(){
       _V_("example_video_1").ready(function(){ 
          myPlayer = this; 
       });
   };
</script>