欧美高清vjcossexo

» js » VideoJs 使用示例,带切换播放源

VideoJs 使用示例,带切换播放源

April 2, 2020 js

直接上代码


<!DOCTYPE html>
<html>
<head>
    <title>videojs支持hls直播实例</title>
    <link href="http://cdn.bootcss.com/video.js/7.7.6/video-js.min.css" rel="stylesheet">
</head>
<body>
<style>
#roomVideo_html5_api{
    width:450px
    height:300px;
}

</style>
    <video id="roomVideo" width="450px" height="300px" class="video-js vjs-default-skin vjs-big-play-centered" x-webkit-airplay="allow" poster="" webkit-playsinline playsinline x5-video-player-type="h5" x5-video-player-fullscreen="true" preload="auto">

    </video>
    <script src="http://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
    <script src="http://cdn.bootcss.com/video.js/7.7.6/video.min.js"></script>
    <script src="http://cdn.bootcss.com/videojs-contrib-hls/5.15.0/videojs-contrib-hls.min.js"></script>
    <script type="text/javascript">
    let player;
    player = videojs('roomVideo',{
            autoplpay: true,
            fluid: true,            
            controls : true,      
            height:300, 
            width:450,
            loop : true,
            // 更多配置.....
        },function onPlayerReady(){
        //显示的当前已播放时间
            /*$(".vjs-current-time").show();
            $(".vjs-duration").show();
            $(".vjs-time-divider").show();
            $(".vjs-remaining-time").hide();*/
            
            videojs.log("播放器已经准备好了!");
            this.src("http://k.bwzybf.com/20191112/kOfrLJTb/index.m3u8");
            //this.play();
            
            var totalTime = 0;
            // 监听播放进度
            player.on('timeupdate', function() {
                //当前播放时长(秒)
                
                
                if(window.obj.tag){  
                    player.currentTime(window.obj.ctime)  
                    player.play();  
                    window.obj.tag=false;  
                }  
                
                var currentTime = Math.floor(player.currentTime());
                totalTime = currentTime;
                if (currentTime > 0 && currentTime > totalTime && (currentTime % 5 == 0)) {
                    //每隔5秒,向服务器提交播放时间(秒)
                    console.log(totalTime)
                }
                
                
            });
            // 使用事件监听
            player.on('ended', function() {
                videojs.log('播放结束了!');
            });    
    });

    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 changeVideo" data-value="0" tabindex="-1" role="menuitemcheckbox">普通</li>'  
        + '<li class="vjs-menu-item changeVideo" data-value="1" tabindex="-1" role="menuitemcheckbox">标清 </li>'  
        + '<li class="vjs-menu-item changeVideo" data-value="2" tabindex="-1" role="menuitemcheckbox">高清 </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; 

$(".changeVideo").click(function(){
    var type = $(this).data("value");
    //切换播放源
});
$(".vjs-subs-caps-button").mouseover(function(){ 
    $(".vjs-menu").show();
}).mouseout(function(){ 
    $(".vjs-menu").hide(); 
});
     
    </script>

</body>
</html>
Title - Artist
0:00
    国产自拍www.letxw.com
    韩国理论电影www.gaopon.com
    小草莓直播www.pamplom.com
    黄瓜app直播www.zzzjkj.com
    草莓视频直播appwww.ylxc168.com
    含羞草appwww.calfrat.com
    小草莓直播www.stemgal.com
    草莓app最新地址www.chrkf.com
    小草莓直播www.tmscrap.com
    丝瓜app下载www.cpwkm.com
    小草莓直播www.tygjgjs.com