首页 > 网页制作 > html5

HTML5 视频播放(video),JavaScript控制视频的实例代码

admin html5 2022-02-06 00:58:57 html5   视频播放   js   视频"

具体代码如下所示:

 




Documenttitle>
<style>
figcaption {
text-align: center;
line-height: 150px;
font-family: "Microsoft Yahei";
font-size: 24px;
}
.player {
width: 720px;
height: 360px;
margin: 10px auto;
border: 1px solid #000;
background-color: #000;
position: relative;
border-radius: 6px;
}
.player video {
width: 720px;
height: 360px;
}
.controls {
width: 700px;
height: 40px;
background-color: rgba(255,255,0,0.3);
position: absolute;
bottom: 10px;
left: 10px;
border-radius: 10px;
}
.switch {
position: absolute;
width: 22px;
height: 22px;
background-color: red;
left: 10px;
top: 9px;
border-radius: 50%;
}
.progress {
width: 432px;
height: 10px;
position: absolute;
background-color: rgba(255,255,255,0.4);
left: 40px;
top: 15px;
border-radius: 4px;
overflow: hidden;
}
.curr-progress {
width: 0%;
height: 100%;
background-color: #fff;
}
.time {
width: 120px;
height: 20px;
text-align: center;
line-height: 20px;
font-size: 12px;
color: #fff;
position: absolute;
left: 510px;
top: 10px;
}
.extend {
position: absolute;
width: 20px;
height: 20px;
background-color: red;
right: 10px;
top: 10px;
}
style>
head>
<body>
<figure>  
<figcaption>视频案例figcaption>
<div class="player">
<video src="11.mp4">video>
<div class="controls">
<a href="#" class="switch">a>
<div class="progress">
<div class="curr-progress">div>
div>
<div class="time">
<span class="curr-time">00:00:00span>/
<span class="total-time">00:00:00span>
div>
<a href="#" class="extend">a>
div>
div>
figure>
<script>
var video = document.querySelector('video');
var playBtn = document.querySelector('.switch');
var currProgress = document.querySelector('.curr-progress');
var currTime = document.querySelector('.curr-time');
var totalTime = document.querySelector('.total-time');
var extend = document.querySelector('.extend');
var tTime = 0;
playBtn.onclick = function() {
if(video.paused){  // 如果视频是暂停的
video.play();    //play()播放  load()重新加载  pause()暂停
}else{
video.pause();
}
}
//当视频能播放(已经通过网络加载完成)时
video.oncanplay = function() {
tTime = video.duration;  //获取视频总时长(单位秒)
var tTimeStr = getTimeStr(tTime);
totalTime.innerHTML = tTimeStr;
}
//当视频当前播放时间更新的时候
video.ontimeupdate = function() {
var cTime = video.currentTime;  //获取当前播放时间 
var cTimeStr = getTimeStr(cTime);
console.log(cTimeStr);
currTime.innerHTML = cTimeStr;
currProgress.style.width = cTime/tTime*100+"%";
}
extend.onclick = function() {
video.webkitRequestFullScreen();  //视频全屏
}
//将以秒为单位的时间变成“00:00:00”格式的字符串
function getTimeStr(time) {
var h = Math.floor(time/3600);
var m = Math.floor(time%3600/60);
var s = Math.floor(time%60);
h = h>=10?h:"0"+h;
m = m>=10?m:"0"+m;
s = s>=10?s:"0"+s;
return h+":"+m+":"+s;
}
script>
body>
html></pre>

<p><span style="color: #ff0000"><strong>总结</strong></span></p>
<p>以上所述是小编给大家介绍的HTML5 视频播放(video),JavaScript控制视频的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对潘少俊衡网站的支持!</p>
						
						
						<span id="art_bot" class="jbTestPos"></span> 
        </div>
        <div class="pagebar">  </div>
        <div class="pcd_ad"><script src=/d/js/acmsd/thea14.js></script></div>
        <div class="mbd_ad">
          <ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-5850285417076520"
     data-ad-slot="9825815134"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
        </div>
        <div class="rights">
          <h5>版权声明</h5>
          <p>本文仅代表作者观点,不代表本站立场。<br>
            本文系作者授权发表,未经许可,不得转载。<br>本文地址:/web/html5/75075.html</p>

<div class="bdsharebuttonbox"><a href="#" class="bds_more" data-cmd="more"></a><a href="#" class="bds_fbook" data-cmd="fbook" title="分享到Facebook"></a><a href="#" class="bds_twi" data-cmd="twi" title="分享到Twitter"></a><a href="#" class="bds_linkedin" data-cmd="linkedin" title="分享到linkedin"></a><a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间"></a><a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a><a href="#" class="bds_douban" data-cmd="douban" title="分享到豆瓣网"></a><a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信"></a><a href="#" class="bds_evernotecn" data-cmd="evernotecn" title="分享到印象笔记"></a></div>
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"1","bdSize":"24"},"share":{},"image":{"viewList":["fbook","twi","linkedin","qzone","tsina","douban","weixin","evernotecn"],"viewText":"分享到:","viewSize":"16"}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='/static/api/js/share.js?v=89860593.js?'];</script>

        </div>


<div class="r-pn-post">
               
<div class="shang"><a title="详解Canvas 跨域脱坑实践" href="/web/html5/75074.html" rel="bookmark" class="prev_p"><span>上一篇 :</span> 详解Canvas 跨域脱坑实践 
</a></div>
<div class="xia"><a href="/web/html5/75076.html" rel="bookmark" class="next_p"><span>下一篇 :</span> HTML5视频播放插件 video.js介绍</a></div>

              
              <div class="clear"></div>
            </div>
      </div>
      <div class="related">
        <h4>相关文章</h4>
        <ul>
        <li> <a href="/aigaoji/175047.html">
            <div class="img"><img src="/d/file/aigaoji/2022-03-28/small288aa0e12ef6fc690dc4083b35e20b171648462490.png" alt="站长们不要接小广告商的js广告,惨痛教训"></div>
            <p>站长们不要接小广告商的js广告,惨痛教训</p>
            </a> </li><li> <a href="/3Dsheji/170640.html">
            <div class="img"><img src="https://img.jbzj.com/file_images/flash/20081061151631277801.jpg" alt="控制Flash8里的flvs视频播放停止"></div>
            <p>控制Flash8里的flvs视频播放停止</p>
            </a> </li><li> <a href="/3Dsheji/166287.html">
            <div class="img"><img src="https://img.jbzj.com/do/uploads/litimg/140626/10455423HK.gif" alt="FLASH CS6组件怎么制作视频播放器?"></div>
            <p>FLASH CS6组件怎么制作视频播放器?</p>
            </a> </li><li> <a href="/Hardware/diannaochangshi/164402.html">
            <div class="img"><img src="https://img.jbzj.com/file_images/article/201207/2012071116054383.png" alt="网络视频播放软件风行的基本使用方法(图文教程)"></div>
            <p>网络视频播放软件风行的基本使用方法(图文教程)</p>
            </a> </li><li> <a href="/Hardware/diannaochangshi/159995.html">
            <div class="img"><img src="https://img.jbzj.com/file_images/article/201411/201411190911593.png" alt="js是什么文件格式?.js文件怎么打开?"></div>
            <p>js是什么文件格式?.js文件怎么打开?</p>
            </a> </li><li> <a href="/websafe/yejie/149951.html">
            <div class="img"><img src="https://img.jbzj.com/file_images/article/201509/2015925104031825.jpg?2015825104041" alt="HTML5安全风险之CORS攻击详解"></div>
            <p>HTML5安全风险之CORS攻击详解</p>
            </a> </li><li> <a href="/websafe/yejie/149948.html">
            <div class="img"><img src="https://img.jbzj.com/file_images/article/201509/201592694628148.jpg?201582694643" alt="HTML5安全风险之Web Storage攻击详解"></div>
            <p>HTML5安全风险之Web Storage攻击详解</p>
            </a> </li><li> <a href="/websafe/yejie/149962.html">
            <div class="img"><img src="https://img.jbzj.com/file_images/article/201509/201592695532854.jpg?201582695542" alt="HTML5安全风险之WebSQL攻击详解"></div>
            <p>HTML5安全风险之WebSQL攻击详解</p>
            </a> </li>        </ul>
      </div>
      <div class="post_comments">
        <div id="comment">
<link href="/skin/ecmspl/css/pl.css" rel="stylesheet">
<div class="showpage" id="plpost">
<table width="100%" border="0" cellpadding="0" cellspacing="0"  style="line-height: 25px; padding: 5px 3px 1px 8px; font-size: 18px;">
<tr><td><strong><font color="#333333">留言与评论(共有 <span id="infocommentnumarea">0</span> 条评论)</font></strong></td></tr>
</table>
<script>
		  function CheckPl(obj)
		  {
		  if(obj.saytext.value=="")
		  {
		  alert("您没什么话要说吗?");
		  obj.saytext.focus();
		  return false;
		  }
		  return true;
		  }
		  </script>
<form action="/e/pl/doaction.php" method="post" name="saypl" id="saypl" onsubmit="return CheckPl(document.saypl)">
<table width="100%" border="0" cellpadding="0" cellspacing="0" id="plpost">
<tr>
<td>
<table width="100%" border="0" cellspacing="10" cellpadding="0">
<tr>
<td>
<script src="/e/pl/loginjspl.php"></script>
<textarea name="saytext" rows="6" id="saytext" placeholder="请遵守互联网相关规定,不要发布广告和违法内容!"></textarea>
<script src="/d/js/js/plface.js"></script>   
<table width='100%' align='left' cellpadding=3 cellspacing=1 bgcolor='#FFF'>
<tr>
<td width="80%" height="40" bgcolor="#FFFFFF">验证码:<input name="key" type="text" class="inputText" size="16" />
<img src="/e/ShowKey/?v=pl" align="absmiddle" name="plKeyImg" id="plKeyImg" onclick="plKeyImg.src='/e/ShowKey/?v=pl&t='+Math.random()" title="看不清楚,点击刷新" /> 
</td> 
<td width="20%" height="40" bgcolor="#FFFFFF"> 
<input name="sumbit" type="submit" value="提交评论" tabindex="6" style="border-radius: 5px;font-size: 16px;background: #e94c3d none repeat scroll 0% 0%;border: 0px none;margin: 0px 16px;padding: 1px 16px;height: 33px;line-height: 30px;color: rgb(255, 255, 255);opacity: 0.95;">
<input name="id" type="hidden" id="id" value="75075" />
<input name="classid" type="hidden" id="classid" value="47" />
<input name="enews" type="hidden" id="enews" value="AddPl" />
<input name="repid" type="hidden" id="repid" value="0" />
<input type="hidden" name="ecmsfrom" value="/web/html5/75075.html">
</td>
</tr>  
</table> 
</td>
</tr>
</table>
</td>
</tr>
</table></form>
	<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
        <tr>
          <td bgcolor="#FFFFFF" id="infocommentarea"></td>
        </tr>
        </table>
 <script src="/e/extend/infocomment/commentajax.php?classid=47&id=75075"></script>
</div>	
        </div>
      </div>
<div class="pcd_ad"><script src=/d/js/acmsd/thea18.js></script></div>
        <div class="mbd_ad">
          <!-- 手机广告位-评论底部广告位新 -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-5850285417076520"
     data-ad-slot="9383780240"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<script type="text/javascript" src="//gg.iwyv.com/production/mh_g/i/static/wi_djn.js"></script>        </div>
    </div>
    <!--@ mainl-->
    
    <div class="mainr">
    <div class="widget widget_ad">
    <script src=/d/js/acmsd/thea14.js></script>
    </div>
      <div class="widget widget_hotpost">
        <h4>热门文章</h4>
        <ul>
                          <li><i class="red">1</i><a href="/web/html5/75947.html" target="_blank">基于HTML5超酷摄像头(HTML5 webcam)拍照功能实现代码</a></li>
                         <li><i class="red">2</i><a href="/web/html5/73062.html" target="_blank">Html5饼图绘制实现统计图的方法</a></li>
                         <li><i class="red">3</i><a href="/web/html5/73961.html" target="_blank">钉钉企业内部H5微应用开发详解</a></li>
                         <li><i>4</i><a href="/web/html5/72861.html" target="_blank">前端监听websocket消息并实时弹出(实例代码)</a></li>
                         <li><i>5</i><a href="/web/html5/72866.html" target="_blank">html实现弹窗的实例</a></li>
                         <li><i>6</i><a href="/web/html5/72874.html" target="_blank">HTML5轮播图全代码</a></li>
                         <li><i>7</i><a href="/web/html5/72875.html" target="_blank">使用PDF.js渲染canvas实现预览pdf的效果示例</a></li>
                         <li><i>8</i><a href="/web/html5/75147.html" target="_blank">HTML5实现自带进度条和滑块滑杆效果</a></li>
                         <li><i>9</i><a href="/web/html5/75201.html" target="_blank">canvas实现按住鼠标移动绘制出轨迹的示例代码</a></li>
                         <li><i>10</i><a href="/web/html5/73050.html" target="_blank">uniapp+Html5端实现PC端适配</a></li>
               </ul>
      </div>
      <div class="widget widget_ad">
    <script src=/d/js/acmsd/thea10.js></script>
    </div>
      <div class="widget widget_previous">
        <h4>最近发表</h4>
        <ul>
                  <li><a href="/ITzixun/178187.html">日本雷蛇官网实习生上错价了?游戏本只卖15950日元?</a></li>
                  <li><a href="/youxi/175574.html">《原神》物归原主又归原主世界任务指南 游戏攻略</a></li>
                  <li><a href="/youxi/175631.html">《原神》振晶的研究第三天试用角色2000分攻略 游戏攻略</a></li>
                  <li><a href="/youxi/175559.html">《原神》2.6版全旋曜玉帛点位说明_蒙德 游戏攻略</a></li>
                  <li><a href="/youxi/175547.html">《原神》2.6版深渊11-1守护镇石技巧 游戏攻略</a></li>
                  <li><a href="/youxi/175604.html">《原神》神里绫华装备搭配推荐 游戏攻略</a></li>
                  <li><a href="/youxi/175516.html">《原神》云堇突破材料获取方法 游戏攻略</a></li>
                  <li><a href="/youxi/175494.html">《原神》世界任务他乡迷失客攻略 游戏攻略</a></li>
                  <li><a href="/youxi/175497.html">《原神》神里绫华全面培养指南 神里绫华技能详解与出装建议 游戏攻略</a></li>
                  <li><a href="/youxi/175460.html">《原神》神里绫人平民向大世界配队思路 游戏攻略</a></li>
                </ul>
      </div>
      <div class="widget widget_ad">
    <script src=/d/js/acmsd/thea11.js></script>
    </div>
      <div class="widget widget_tags">
        <h4>标签列表</h4>
        <ul>
            <li class="submenu"><a target="_blank" href="/e/tags/?tagname=%E5%BC%80%E6%94%BE%E4%B8%96%E7%95%8C">开放世界</a></li>         <li class="submenu"><a target="_blank" href="/e/tags/?tagname=%E6%B2%99%E7%9B%92">沙盒</a></li>         <li class="submenu"><a target="_blank" href="/e/tags/?tagname=win10">win10</a></li>         <li class="submenu"><a target="_blank" href="/e/tags/?tagname=3D%E8%AE%BE%E8%AE%A1">3D设计</a></li>         <li class="submenu"><a target="_blank" href="/e/tags/?tagname=PS">PS</a></li>         <li class="submenu"><a target="_blank" href="/e/tags/?tagname=%E9%AC%BC%E8%B0%B7%E5%85%AB%E8%8D%92">鬼谷八荒</a></li>         <li class="submenu"><a target="_blank" href="/e/tags/?tagname=win7">win7</a></li>         <li class="submenu"><a target="_blank" href="/e/tags/?tagname=%E6%89%8B%E6%B8%B8">手游</a></li>         <li class="submenu"><a target="_blank" href="/e/tags/?tagname=%E5%9B%A2%E9%98%9F%E7%AB%9E%E6%8A%80">团队竞技</a></li>         <li class="submenu"><a target="_blank" href="/e/tags/?tagname=%E5%8E%9F%E7%A5%9E">原神</a></li>         <li class="submenu"><a target="_blank" href="/e/tags/?tagname=%E4%BA%8C%E6%AC%A1%E5%85%83%E6%B8%B8%E6%88%8F">二次元游戏</a></li>         <li class="submenu"><a target="_blank" href="/e/tags/?tagname=%E7%AD%96%E7%95%A5">策略</a></li>         <li class="submenu"><a target="_blank" href="/e/tags/?tagname=%E7%94%B5%E8%84%91%E5%B8%B8%E8%AF%86">电脑常识</a></li>         <li class="submenu"><a target="_blank" href="/e/tags/?tagname=%E7%8E%8B%E8%80%85%E8%8D%A3%E8%80%80">王者荣耀</a></li>         <li class="submenu"><a target="_blank" href="/e/tags/?tagname=%E7%85%A7%E7%89%87%E5%A4%84%E7%90%86">照片处理</a></li>         <li class="submenu"><a target="_blank" href="/e/tags/?tagname=MySQL">MySQL</a></li>         <li class="submenu"><a target="_blank" href="/e/tags/?tagname=%E5%90%83%E9%B8%A1">吃鸡</a></li>         <li class="submenu"><a target="_blank" href="/e/tags/?tagname=%E7%AC%94%E8%AE%B0%E6%9C%AC">笔记本</a></li>         <li class="submenu"><a target="_blank" href="/e/tags/?tagname=%E7%BB%9D%E5%9C%B0%E6%B1%82%E7%94%9F%E5%A4%A7%E9%80%83%E6%9D%80">绝地求生大逃杀</a></li>         <li class="submenu"><a target="_blank" href="/e/tags/?tagname=%E5%B0%84%E5%87%BB%E7%AB%9E%E4%BA%89">射击竞争</a></li>            </ul>
      </div>
<div class="widget widget_ad">
    <script src=/d/js/acmsd/thea12.js></script>
    </div>
    </div>
  </div>
</div>
<script type="text/javascript"> 
// JavaScript Document
function goTopEx(){
        var obj=document.getElementById("goTopBtn");
        function getScrollTop(){
                return document.documentElement.scrollTop || document.body.scrollTop;
            }
        function setScrollTop(value){
            if(document.documentElement.scrollTop){
                    document.documentElement.scrollTop=value;
                }else{
                    document.body.scrollTop=value;
                }
                
            }    
        window.onscroll=function(){getScrollTop()>0?obj.style.display="":obj.style.display="none";
                    var h=document.body.scrollHeight - getScrollTop() - obj.offsetTop - obj.offsetHeight;
                    obj.style.bottom=0+"px";
                    if(h<350){
                        obj.style.bottom=340+"px";
                        obj.style.top="auto";
                    }

        
        }
        obj.onclick=function(){

            var goTop=setInterval(scrollMove,10);
            function scrollMove(){
                    setScrollTop(getScrollTop()/1.1);
                    if(getScrollTop()<1)clearInterval(goTop);

                }
        }
    }

</script> 
<!--向上 -->

<div id="jz52top" > <span>
  <DIV style="DISPLAY: none" id="goTopBtn" ><a title="返回顶部" class="jz52topa" ><b>返回顶部</b></a></DIV>
  </span> 
  <SCRIPT type=text/javascript>goTopEx();</SCRIPT> 
  <span>
  <ul id="navmenu">
    <li><a title="QR Code"  class="jzqr"  ><b>QR Code</b></a>
      <ul>
        <div id="jzqrn"> <img src="/skin/ecms172/images/weixin.png"  width="228" height="228" />
          <p>打开手机扫描上面的二维码</p>
        </div>
      </ul>
    </li>
  </ul>
  </span> </div>
<!--向上完 --> 

<!-- 底部广告--> 

<!-- 底部广告--> 

<!--底部信息 -->
<div class="ft_wp">
  <div id="ft" class="wp cl ftddd" >
    <div class="ft_info" >
      <div class="ft_z1">
        <p>潘少俊衡</p>
      
        <h3 class="ft_z_zdxx_zx">
          <script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?1cc50873f5e983e8073d99a425b87921";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>
          <span class="pipe"> | </span>
          桂ICP备2023010378号-4        </h3>
        <h2 class="ft_z_zdxx_zx">
          <p style="font-size:12px;">Powered By <a href="https://www.iwyv.com/" title="潘少俊衡" target="_blank">EmpireCMS</a> </p>
        </h2>
      </div>
 
     <div class="ft_z2">


      </div>
 
      <div class="ft_z2">


<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XFMBHZNTEL"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-XFMBHZNTEL');
</script>


        <p><a target="_blank" href="https://www.iixiang.com/">爱享小站</a></p>
<p><a target="_blank" href="https://www.sdzdyn.com/">中德益农</a></p>
       <p><a target="_blank" href="https://www.guujie.com">谷姐神农</a></p>
<p><a target="_blank" href="https://huanyafeiliao.com/">环亚肥料</a></p>
      </div>
      <div class="ft_z2">
    
 <p><a target="_blank" href="https://beian.miit.gov.cn/Integrated/index">桂ICP备2023010378号-4</a></p>
   <p><a href="https://beian.miit.gov.cn" title="桂公网备 45012202000125号" target="_blank">桂公网备 45012202000125号</a></p>    
      </div>
      <div class="ft_z2">
      
        <p><a target="_blank" href="https://www.iwyv.com/panshaoSEO/1277.html">联系我们</a></p>
      </div>
      <div class="ft_z2">
        <p><a target="_blank" href="https://www.iwyv.com/panshaoSEO/1277.html">商业合作</a></p>
 
        <p><a target="_blank" href="https://www.iwyv.com/panshaoSEO/1277.html">广告投放</a></p>
        <p><a target="_blank" href="/tgxz/">投稿须知</a></p>
      </div>
      <div class="ft_bx"style="left:335px;"> </div>
      <div class="ft_bx  ft_t1"> </div>
      <div class="ft_bx  ft_t2"> </div>
      <div class="ft_bx  ft_t3"> </div>
      <div class="ft_bx  ft_t4"> </div>
      <div class="ft_z3">
        <dd> <span><img src="/skin/ecms172/images/weixin.png"  width="75" height="72.2" /></span>
          <p> 
            <!-- 引用官方图标 -->
            
         
          <!-- 引用官方图标百度统计 -->


          </p>
          <p>使用手机软件扫描微信二维码</p>
          <p>关注我们可获取更多热点资讯</p>
          <p>感谢潘少俊衡友情技术支持</p>
        </dd>
      </div>
    </div>
  </div>
</div>
<div class="clear"></div>
<!--底部信息完 --> 

<script src="/skin/ecms172/js/common.min.js" type="text/javascript"></script> 
<script></script>
</body>
</html>