1. 程式人生 > >videojs集成--播放rtmp流

videojs集成--播放rtmp流

oot des head enter max size copyto meta 進行

之前說到已經把流推送過來了,這時候就可以使用videojs來進行顯示播放。

首先要先有一個文件,那就是video-js.swf

因為,這種播放方式html已經不能很好的進行播放了,需要用到flash來播放,videojs在這個地方就用到了這個。

代碼就是下面這樣。

裏面一些細節註釋都有。

重點就是看<video>標簽裏面的內容

[html] view plain copy
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta http-equiv="Access-Control-Allow-Origin" content="*">
  5. <meta charset="utf-8">
  6. <meta name="description" content="Opencast Media Player">
  7. <meta name="author" content="Opencast">
  8. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  9. <title>RTMP播放</title>
  10. <link rel="stylesheet" type="text/css" href="css/bootstrap/css/bootstrap.css">
  11. <link rel="stylesheet" type="text/css" href="css/core_global_style.css">
  12. <script src="videojs/jquery.js"></script>
  13. <script src="videojs/video.js"></script>
  14. <link href="videojs/video-js.css" rel="stylesheet">
  15. <script>
  16. videojs.options.flash.swf = "videojs/video-js.swf";//flash路徑,有一些html播放不了的視頻,就需要用到flash播放。這一句話要加在在videojs.js引入之後使用
  17. </script>
  18. </head>
  19. <body >
  20. <div id="engage_view" style="display: block;">
  21. <div id="engage_content">
  22. <div id="engage_resize_container">
  23. <div id="engage_video">
  24. <!-- theodul video videojs plugin desktop mode controls preload="auto"
  25. vjs-big-play-centered 播放按鈕居中
  26. poster默認的顯示界面,就是還沒點播放,給你顯示的界面
  27. controls
  28. preload="auto" 是否提前加載
  29. autoplay 自動播放
  30. loop=true 自動循環
  31. data-setup=‘{"example_option":true}‘ 可以把一些屬性寫到這個裏面來,如data-setup={"autoplay":true}
  32. -->
  33. <video id="my-video" class="video-js vjs-default-skin vjs-big-play-centered"
  34. poster="videojs/eguidlogo.png" width="800" height="600"
  35. >
  36. <!--
  37. <source src="../output.mp4" type=‘video/mp4‘> mp4格式
  38. <source src=‘rtmp://127.0.0.1/hls/test‘ type=‘rtmp/flv‘/> rtmp格式
  39. <source src=‘http://127.0.0.1/hls/test.m3u8‘ type=‘application/x-mpegURL‘/> m3u8格式
  40. <source src=‘http://live.hkstv.hk.lxdns.com/live/hks/playlist.m3u8‘ type=‘application/x-mpegURL‘/> m3u8格式,可用
  41. -->
  42. <source src=‘rtmp://live.hkstv.hk.lxdns.com/live/hks‘ type=‘rtmp/flv‘/>
  43. </video>
  44. <!-- http://live.hkstv.hk.lxdns.com/live/hks/playlist.m3u8 可用的m3u8地址 -->
  45. <!-- rtmp://live.hkstv.hk.lxdns.com/live/hks 可用的rtmp地址-->
  46. </div>
  47. </div>
  48. <!-- timeline plugin container -->
  49. </div>
  50. </div>
  51. <div class="clear"></div>
  52. <div id="information_wrapper">
  53. <!-- description plugin container -->
  54. <div id="engage_description"><!-- theodul description plugin desktop mode -->
  55. <div id="engage_basic_description"></div>
  56. </div>
  57. </div>
  58. <div class="tab-pane" id="engage_Slide_text_tab"><!-- theodul tab slidetext plugin embed mode -->
  59. </div>
  60. <script src="videojs/videojs-media-sources.min.js"></script>
  61. <!-- <script src="videojs/videojs-contrib-hls.min.js"></script>-->
  62. <script src="videojs/videojs.hls.min.js"></script>
  63. <script>
  64. //播放的話,就直接使用下面2行
  65. //後面註釋的那些其實也是可用用的,不過剛開始集成,越簡單越好
  66. var player = videojs(‘my-video‘);
  67. player.play();
  68. /*
  69. (function ($) {
  70. var resetVideoSize = function (myPlayer) {
  71. var videoJsBoxWidth = $(".video-js").width();
  72. var ratio = 1440 / 900;
  73. var videoJsBoxHeight = videoJsBoxWidth / ratio;
  74. myPlayer.height(videoJsBoxHeight);
  75. }
  76. $(window).on("resize", function () {
  77. resetVideoSize(myPlayer);
  78. });
  79. myPlayer.play();
  80. })(jQuery)
  81. function changeSrc() {
  82. var src = "http://127.0.0.1/hls/test.m3u8";
  83. var myPlayera = videojs("my-video");
  84. $("#my-video").attr("src", "rtmp://live.hkstv.hk.lxdns.com/live/hks")
  85. myPlayera.src("rtmp://live.hkstv.hk.lxdns.com/live/hks"); //重新初始化視頻地址
  86. myPlayera.load("rtmp://live.hkstv.hk.lxdns.com/live/hks"); //重新加載
  87. }
  88. */
  89. function changeSrc(src) {
  90. var myPlayera = videojs("my-video");
  91. //$("#videojs_videodisplay_presentation_html5_api").attr("src", "rtmp://live.hkstv.hk.lxdns.com/live/hks")
  92. myPlayera.src(src); //重新初始化視頻地址
  93. myPlayera.load(src); //重新加載
  94. }
  95. </script>
  96. </body>
  97. </html>

videojs集成--播放rtmp流