本文主要是介绍Video.js中m3u8视频清晰度切换,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
原文地址:http://blog.csdn.net/chenyongtu110/article/details/77181081
完成测试代码
<!DOCTYPE HTML>
<html>
<head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>视频控制</title> <link href="https://unpkg.com/video.js/dist/video-js.css" rel="stylesheet"> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script> <script src="https://unpkg.com/video.js/dist/video.js"></script> <script src="https://unpkg.com/videojs-contrib-hls/dist/videojs-contrib-hls.js"></script>
</head> <body> <video id="my_video_1" class="video-js vjs-default-skin" controls preload="auto" width="640" height="268" data-setup='{}'> <source src="http://localhost/video/c/1928.m3u8" type="application/x-mpegURL"> </video>
<br/> </body> <script type="text/javascript"> window.οnlοad=function(){ var videoPanelMenu = $(".vjs-fullscreen-control"); videoPanelMenu.before('<div class="vjs-subs-caps-button vjs-menu-button vjs-menu-button-popup vjs-control vjs-button" aria-live="polite" aria-expanded="false" aria-haspopup="true">' + '<div class="vjs-menu" role="presentation">' + '<ul class="vjs-menu-content" role="menu">' + '<li class="vjs-menu-item" tabindex="-1" role="menuitemcheckbox" οnclick="changeVideo(1)">普通</li>' + '<li class="vjs-menu-item" tabindex="-1" role="menuitemcheckbox" οnclick="changeVideo(2)">标清 </li>' + '<li class="vjs-menu-item" tabindex="-1" role="menuitemcheckbox" οnclick="changeVideo(3)">高清 </li>' + '</ul></div>' +' <button class="vjs-subs-caps-button vjs-control vjs-button" type="button" aria-live="polite" title="清晰度切换" aria-disabled="false">' +' <span aria-hidden="true" class="vjs-icon-placeholder"></span><span class="vjs-control-text">清晰度切换</span>' +' </button>' +'</div>' ); var obj={tag:false,ctime:0}; window.obj=obj; var myPlayer=videojs.getPlayers()['my_video_1']; myPlayer.on("timeupdate", function(){ if(window.obj.tag){ videojs("my_video_1").currentTime(window.obj.ctime) videojs("my_video_1").play(); window.obj.tag=false; } //视频打点 var ctime_=videojs("my_video_1").currentTime().currentTime(); if(ctime_==60){ videojs("my_video_1").currentTime(ctime_+1); //do something } }); } function changeVideo(type){ var ctime=videojs("my_video_1").currentTime(); if(type==1){ videojs("my_video_1").src([{type: "application/x-mpegURL", src: "http://localhost/video/LD/1928.m3u8" }]); videojs("my_video_1").play(); } if(type==2){ videojs("my_video_1").src([{type: "application/x-mpegURL", src: "http://localhost/video/C/1928.m3u8" }]); videojs("my_video_1").play(); } if(type==3){ videojs("my_video_1").src([{type: "application/x-mpegURL", src: "http://localhost/video/HD/1928.m3u8" }]); videojs("my_video_1").play(); } window.obj.ctime=ctime; window.obj.tag=true; } </script>
</html>
这篇关于Video.js中m3u8视频清晰度切换的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!