videojs 播放.M3U8格式视频

ゝ一世哀愁。 2022-03-08 19:30 1310阅读 0赞

1.原生video标签网页端只支持MP4、OGG、WebM的视频格式
2.直播的视频格式一般为.m3u8,如果不行对video进行格外处理,可以采用video.js插件
3.video.js须配合第三方的videojs库videojs-contrib-hls.js来播放.m3u8视频

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>videoJs</title>
  6. <link rel="stylesheet" type="text/css" href="css/video-js.css">
  7. <script src="js/video.min.js"></script>
  8. <script src="https://unpkg.com/videojs-contrib-hls/dist/videojs-contrib-hls.js"></script>
  9. </head>
  10. <body>
  11. <section id="videoPlayer">
  12. <video id="example-video" width="600" height="300" class="video-js vjs-default-skin vjs-big-play-centered" poster="">
  13. <source src="http://rm03.wscdn.hls.xiaoka.tv/live/fczjp0Dc_J60VGMN/playlist.m3u8" type="application/x-mpegURL" id="target">
  14. </video>
  15. </section>
  16. <script type="text/javascript">
  17. var player = videojs('example-video', { "poster": "", "controls": "true" }, function() {
  18. this.on('play', function() {
  19. console.log('正在播放');
  20. });
  21. //暂停--播放完毕后也会暂停
  22. this.on('pause', function() {
  23. console.log("暂停中")
  24. });
  25. // 结束
  26. this.on('ended', function() {
  27. console.log('结束');
  28. })
  29. });
  30. </script>
  31. </body>
  32. </html>

发表评论

表情:
评论列表 (有 0 条评论,1310人围观)

还没有评论,来说两句吧...

相关阅读