srs_player.html 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>SRS</title>
  5. <meta charset="utf-8">
  6. <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
  7. <style>
  8. body{
  9. padding-top: 55px;
  10. }
  11. #my_modal_footer {
  12. margin-top: -20px;
  13. padding-top: 3px;
  14. }
  15. #main_modal {
  16. margin-top: -60px;
  17. }
  18. .div_play_time {
  19. margin-top: 10px;
  20. }
  21. #pb_buffer_bg {
  22. margin-top: -4px;
  23. margin-bottom: 10px;
  24. }
  25. </style>
  26. </head>
  27. <body>
  28. <img src='https://ossrs.net/gif/v1/sls.gif?site=ossrs.net&path=/player/srsplayer'/>
  29. <div class="navbar navbar-fixed-top">
  30. <div class="navbar-inner">
  31. <div class="container">
  32. <a id="srs_index" class="brand" href="#">SRS</a>
  33. <div class="nav-collapse collapse">
  34. <ul class="nav">
  35. <li class="active"><a id="nav_srs_player" href="srs_player.html">SRS播放器</a></li>
  36. <li><a id="nav_rtc_player" href="rtc_player.html">RTC播放器</a></li>
  37. <li><a id="nav_rtc_publisher" href="rtc_publisher.html">RTC推流</a></li>
  38. <li><a href="http://ossrs.net/srs.release/releases/app.html">iOS/Andriod</a></li>
  39. <!--<li><a id="nav_srs_publisher" href="srs_publisher.html">SRS编码器</a></li>-->
  40. <!--<li><a id="nav_srs_chat" href="srs_chat.html">SRS会议</a></li>-->
  41. <!--<li><a id="nav_srs_bwt" href="srs_bwt.html">SRS测网速</a></li>-->
  42. <!--li><a id="nav_vlc" href="vlc.html">VLC播放器</a></li>-->
  43. <li><a id="nav_gb28181" href="srs_gb28181.html">GB28181</a></li>
  44. <li>
  45. <a href="https://github.com/ossrs/srs">
  46. <img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/ossrs/srs?style=social">
  47. </a>
  48. </li>
  49. </ul>
  50. </div>
  51. </div>
  52. </div>
  53. </div>
  54. <div class="container">
  55. <div id="main_content">
  56. <div id="main_info" class="alert alert-info fade in">
  57. <button type="button" class="close" data-dismiss="alert">×</button>
  58. <strong><span>Usage:</span></strong> <span>输入HTTP-FLV/HLS地址后点击“播放视频”即可播放视频</span>
  59. </div>
  60. <div class="form-inline">
  61. <div>
  62. URL:
  63. <input type="text" id="txt_url" class="input-xxlarge" value="">
  64. <button class="btn btn-primary" id="btn_play">播放视频</button>
  65. </div>
  66. <p></p>
  67. <div>
  68. <video id="video_player" width="100%" autoplay controls></video>
  69. </div>
  70. <p>
  71. 分享:<a href="#" id="link_url" target="_blank">请右键拷贝此链接</a>
  72. </p>
  73. <div id="main_tips">
  74. <p></p>
  75. <p>
  76. 推荐的其他播放器:
  77. <ul>
  78. <li><a href="http://bilibili.github.io/flv.js/demo">flv.js</a>,H5/MSE播放HTTP-FLV</li>
  79. <li><a href="https://hls-js.netlify.com/demo">hls.js</a>,H5/MSE播放HLS</li>
  80. <li><a href="http://reference.dashif.org/dash.js/nightly/samples/dash-if-reference-player/index.html">dash.js</a>,H5/MSE播放MPEG-DASH</li>
  81. </ul>
  82. </p>
  83. </div>
  84. </div>
  85. </div>
  86. <div name="detect_flash">
  87. <div id="main_flash_alert" class="alert alert-danger fade in hide">
  88. <button type="button" class="close" data-dismiss="alert">×</button>
  89. <p>
  90. <a href="https://www.adobe.com/products/flashplayer/end-of-life.html" target="_blank">Flash已死</a>,
  91. 无法播放RTMP流,可用VLC播放器播放。
  92. </p>
  93. <ul>
  94. <li>若希望做低延迟直播(3-5秒),可用HTTP-FLV,播放器用<a href="http://bilibili.github.io/flv.js/demo">flv.js</a>,H5/MSE播放HTTP-FLV</li>
  95. <li>若对延迟不敏感(5-10秒),跨平台比较好,可用HLS,播放器用<a href="https://hls-js.netlify.com/demo">hls.js</a>,H5/MSE播放HLS</li>
  96. <li>若希望超低延迟(1秒内),只需要支持主流的浏览器,可用WebRTC,播放器用<a href="rtc_player.html">RTC播放器</a></li>
  97. </ul>
  98. <p>
  99. 更多信息,参考<a href="https://mp.weixin.qq.com/s/oYn5q4fF9afaged23Ueudg" target="_blank">没有Flash如何做直播?</a>
  100. </p>
  101. </div>
  102. </div>
  103. <footer>
  104. <p></p>
  105. <p><a href="https://github.com/ossrs/srs">SRS Team &copy; 2013</a></p>
  106. </footer>
  107. </div>
  108. </body>
  109. <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
  110. <script type="text/javascript" src="js/bootstrap.min.js"></script>
  111. <script type="text/javascript" src="js/flv-1.5.0.min.js"></script>
  112. <script type="text/javascript" src="js/hls-0.14.17.min.js"></script>
  113. <script type="text/javascript" src="js/json2.js"></script>
  114. <script type="text/javascript" src="js/srs.page.js"></script>
  115. <script type="text/javascript" src="js/srs.log.js"></script>
  116. <script type="text/javascript" src="js/srs.utility.js"></script>
  117. <script type="text/javascript" src="js/winlin.utility.js"></script>
  118. <script type="text/javascript">
  119. var flvPlayer = null;
  120. var hlsPlayer = null;
  121. var stopPlayers = function () {
  122. if (flvPlayer) {
  123. flvPlayer.destroy();
  124. flvPlayer = null;
  125. }
  126. if (hlsPlayer) {
  127. hlsPlayer.destroy();
  128. hlsPlayer = null;
  129. }
  130. };
  131. var hide_for_error = function () {
  132. $('#main_flash_alert').show();
  133. $('#main_info').hide();
  134. $('#main_tips').hide();
  135. $('#video_player').hide();
  136. //$('#btn_play').hide();
  137. stopPlayers();
  138. };
  139. var show_for_ok = function () {
  140. $('#main_flash_alert').hide();
  141. $('#main_info').show();
  142. $('#main_tips').show();
  143. $('#video_player').show();
  144. //$('#btn_play').show();
  145. };
  146. var apply_url_change = function() {
  147. var r = parse_rtmp_url($("#txt_url").val());
  148. var url = window.location.protocol + "//" + query.host + query.pathname + "?autostart=true"
  149. + "&app=" + r.app + "&stream=" + r.stream + "&server=" + r.server + "&port=" + r.port;
  150. url += (query.shp_identify) ? "&shp_identify=" + query.shp_identify : '';
  151. url += (r.vhost === "__defaultVhost__") ? "&vhost=" + r.server : "&vhost=" + r.vhost;
  152. url += (r.schema !== "rtmp") ? "&schema=" + r.schema : '';
  153. url += (query.buffer) ? "&buffer=" + query.buffer : '';
  154. url += (query.api_port) ? "&api_port=" + query.api_port : '';
  155. var queries = user_extra_params(query);
  156. queries = user_extra_params(r, queries);
  157. if (queries && queries.length) {
  158. url += '&' + queries.join('&');
  159. }
  160. $("#player_url").text($("#txt_url").val()).attr("href", url);
  161. $("#link_url").attr("href", url);
  162. // For RTMP, not support.
  163. if (r.schema === 'rtmp') {
  164. hide_for_error();
  165. return;
  166. }
  167. return r;
  168. };
  169. var start_play = function (r) {
  170. stopPlayers();
  171. if (!r) return;
  172. // Start play HTTP-FLV.
  173. if (r.stream.indexOf('.flv') > 0) {
  174. if (!flvjs.isSupported()) {
  175. hide_for_error();
  176. return;
  177. }
  178. show_for_ok();
  179. flvPlayer = flvjs.createPlayer({type: 'flv', url: r.url});
  180. flvPlayer.attachMediaElement(document.getElementById('video_player'));
  181. flvPlayer.load();
  182. flvPlayer.play();
  183. return;
  184. }
  185. // Start play HLS.
  186. if (r.stream.indexOf('.m3u8') > 0) {
  187. if (!Hls.isSupported()) {
  188. hide_for_error();
  189. return;
  190. }
  191. show_for_ok();
  192. hlsPlayer = new Hls();
  193. hlsPlayer.loadSource(r.url);
  194. hlsPlayer.attachMedia(document.getElementById('video_player'));
  195. return;
  196. }
  197. console.error('不支持的URL', r.url, r);
  198. $('#video_player').hide();
  199. };
  200. $("#txt_url").change(function(){
  201. apply_url_change();
  202. });
  203. $("#btn_play").click(function(){
  204. $('#video_player').prop('muted', false);
  205. var r = apply_url_change();
  206. start_play(r);
  207. });
  208. /****
  209. * The parameters for this page:
  210. * schema, the protocol schema, rtmp or http.
  211. * server, the ip of the url.
  212. * port, the rtmp port of url.
  213. * vhost, the vhost of url, can equals to server.
  214. * app, the app of url.
  215. * stream, the stream of url, can endwith .flv or .mp4 or nothing for RTMP.
  216. * autostart, whether auto play the stream.
  217. * buffer, the buffer time in seconds.
  218. * extra params:
  219. * shp_identify, hls+ param.
  220. * for example:
  221. * http://localhost:8088/players/srs_player.html?vhost=ossrs.net&app=live&stream=livestream&server=ossrs.net&port=1935&autostart=true&schema=rtmp
  222. * http://localhost:8088/players/srs_player.html?vhost=ossrs.net&app=live&stream=livestream.flv&server=ossrs.net&port=8080&autostart=true&schema=http
  223. */
  224. var query = parse_query_string();
  225. // get the vhost and port to set the default url.
  226. // url set to: http://localhost:8080/live/livestream.flv
  227. srs_init_flv("#txt_url");
  228. if (query.autostart === "true") {
  229. $('#video_player').prop('muted', true);
  230. console.warn('For autostart, we should mute it, see https://www.jianshu.com/p/c3c6944eed5a ' +
  231. 'or https://developers.google.com/web/updates/2017/09/autoplay-policy-changes#audiovideo_elements');
  232. var r = apply_url_change();
  233. start_play(r);
  234. } else {
  235. $('#video_player').hide();
  236. }
  237. </script>
  238. </html>