播放M3U8的js代码
Posted ComputerVip
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了播放M3U8的js代码相关的知识,希望对你有一定的参考价值。
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script> <!-- Or if you want a more recent canary version --> <!-- <script src="https://cdn.jsdelivr.net/npm/hls.js@canary"></script> --> <video id="video"></video> <script> var video = document.getElementById(‘video‘); if(Hls.isSupported()) { var hls = new Hls(); hls.loadSource(‘https://路径/index.m3u8‘); hls.attachMedia(video); hls.on(Hls.Events.MANIFEST_PARSED,function() { video.play(); }); } else if (video.canPlayType(‘application/vnd.apple.mpegurl‘)) { video.src = ‘https://路径/index.m3u8‘; video.addEventListener(‘loadedmetadata‘,function() { video.play(); }); } </script>
ckplayer播放器播放M3U8视频
<div id="a1"></div> <script type="text/javascript" src="/ckplayer/ckplayer.js" charset="utf-8"></script> <script type="text/javascript"> var flashvars={ f:‘m3u8.swf‘, a:‘http://ztest.qiniudn.com/sintel.m3u8‘, s:4, c:0 }; var params={bgcolor:‘#FFF‘,allowFullScreen:true,allowScriptAccess:‘always‘,wmode:‘transparent‘}; var video=[‘http://ztest.qiniudn.com/sintel.m3u8‘]; CKobject.embed(‘/ckplayer/ckplayer.swf‘,‘a1‘,‘ckplayer_a1‘,‘100%‘,‘100%‘,false,flashvars,video,params); </script>
以上是关于播放M3U8的js代码的主要内容,如果未能解决你的问题,请参考以下文章
H5播放m3u8 - <video><source src=“xx.m3u8“/></video> - 使用video.js+HLS插件