srs_player.html 9.6 KB

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