2
0

srs_player_deprecated.html 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  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. #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='//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">LivePlayer</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 name="detect_flash">
  56. <div id="main_flash_alert" class="alert alert-danger fade in hide">
  57. <button type="button" class="close" data-dismiss="alert">×</button>
  58. <strong><p>Usage:</p></strong>
  59. <p>
  60. 请点击下面的图标,启用Flash
  61. </p>
  62. <p>
  63. 若没有见到这个图标,Chrome浏览器请打开
  64. <span class="text-info">chrome://settings/content/flash</span> 并修改为"Ask first"。
  65. </p>
  66. </div>
  67. <div id="main_flash_hdr" class="hide">
  68. </div>
  69. </div>
  70. <div id="main_content" class="hide">
  71. <div class="alert alert-info fade in">
  72. <button type="button" class="close" data-dismiss="alert">×</button>
  73. <strong><span>Usage:</span></strong> <span>输入RTMP/HTTP-FLV/HLS地址后点击“播放视频”即可播放视频</span>
  74. </div>
  75. <div class="form-inline">
  76. URL:
  77. <input type="text" id="txt_url" class="input-xxlarge" value="">
  78. <button class="btn btn-primary" id="btn_play">播放视频</button>
  79. <button class="btn" id="btn_generate_link">生成链接</button>
  80. <p></p>
  81. <p>
  82. 推荐的其他播放器:
  83. <ul>
  84. <li><a href="http://bilibili.github.io/flv.js/demo">flv.js</a>,H5/MSE播放HTTP-FLV</li>
  85. <li><a href="https://hls-js.netlify.com/demo">hls.js</a>,H5/MSE播放HLS</li>
  86. <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>
  87. </ul>
  88. </p>
  89. </div>
  90. <div id="link_modal" class="modal hide fade">
  91. <div class="modal-header">
  92. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
  93. <h3><a href="https://github.com/ossrs/srs">SRS Link Generator</a></h3>
  94. </div>
  95. <div class="modal-body">
  96. <div class="form-horizontal">
  97. <div class="control-group">
  98. <label class="control-label" for="link_server">服务器地址</label>
  99. <div class="controls">
  100. <span id="link_server" class="span4 uneditable-input"></span>
  101. </div>
  102. </div>
  103. <div class="control-group">
  104. <label class="control-label" for="link_port">服务器端口</label>
  105. <div class="controls">
  106. <span id="link_port" class="span2 uneditable-input"></span>
  107. </div>
  108. </div>
  109. <div class="control-group">
  110. <label class="control-label" for="link_vhost">RTMP Vhost</label>
  111. <div class="controls">
  112. <span id="link_vhost" class="span4 uneditable-input"></span>
  113. </div>
  114. </div>
  115. <div class="control-group">
  116. <label class="control-label" for="link_app">RTMP App</label>
  117. <div class="controls">
  118. <span id="link_app" class="span4 uneditable-input"></span>
  119. </div>
  120. </div>
  121. <div class="control-group">
  122. <label class="control-label" for="link_stream">RTMP Stream</label>
  123. <div class="controls">
  124. <span id="link_stream" class="span4 uneditable-input"></span>
  125. </div>
  126. </div>
  127. <div class="control-group">
  128. <label class="control-label" for="link_rtmp">RTMP地址</label>
  129. <div class="controls">
  130. <span id="link_rtmp" class="span4 uneditable-input"></span>
  131. </div>
  132. </div>
  133. <div class="control-group">
  134. <label class="control-label" for="link_url">播放链接地址</label>
  135. <div class="controls">
  136. <div style="margin-top:5px;"><a href="#" id="link_url" target="_blank">请右键拷贝此链接地址.</a></div>
  137. </div>
  138. </div>
  139. </div>
  140. </div>
  141. <div class="modal-footer"></div>
  142. </div>
  143. <div id="main_modal" class="modal hide fade">
  144. <div class="modal-header">
  145. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
  146. <h3><a href="https://github.com/ossrs/srs">SrsPlayer</a></h3>
  147. </div>
  148. <div class="modal-body">
  149. <div id="player"></div>
  150. <div class="progress progress-striped active" id="pb_buffer_bg">
  151. <div class="bar" style="width: 0%;" id="pb_buffer"></div>
  152. </div>
  153. </div>
  154. <div class="modal-footer" id="my_modal_footer">
  155. <div>
  156. <div class="btn-group dropup">
  157. <button class="btn dropdown-toggle" data-toggle="dropdown">
  158. 全屏比例大小<span class="caret"></span>
  159. </button>
  160. <ul class="dropdown-menu">
  161. <li><a id="btn_fs_size_screen_100" href="#">屏幕大小(100%)</a></li>
  162. <li><a id="btn_fs_size_screen_75" href="#">屏幕大小(75%)</a></li>
  163. <li><a id="btn_fs_size_screen_50" href="#">屏幕大小(50%)</a></li>
  164. <li><a id="btn_fs_size_video_100" href="#">视频大小(100%)</a></li>
  165. <li><a id="btn_fs_size_video_75" href="#">视频大小(75%)</a></li>
  166. <li><a id="btn_fs_size_video_50" href="#">视频大小(50%)</a></li>
  167. </ul>
  168. </div>
  169. <div class="btn-group dropup">
  170. <button class="btn dropdown-toggle" data-toggle="dropdown">显示比例<span class="caret"></span></button>
  171. <ul class="dropdown-menu">
  172. <li><a id="btn_dar_original" href="#">视频原始比例</a></li>
  173. <li><a id="btn_dar_21_9" href="#">宽屏影院(21:9)</a></li>
  174. <li><a id="btn_dar_16_9" href="#">宽屏电视(16:9)</a></li>
  175. <li><a id="btn_dar_4_3" href="#">窄屏(4:3)</a></li>
  176. <li><a id="btn_dar_fill" href="#">填充(容器比例)</a></li>
  177. </ul>
  178. </div>
  179. <div class="btn-group dropup">
  180. <button class="btn dropdown-toggle" data-toggle="dropdown">缓冲区大小<span class="caret"></span></button>
  181. <ul class="dropdown-menu">
  182. <li><a id="btn_bt_0_1" href="#">0.1秒(实时)</a></li>
  183. <li><a id="btn_bt_0_2" href="#">0.2秒(实时)</a></li>
  184. <li><a id="btn_bt_0_3" href="#">0.3秒(实时)</a></li>
  185. <li><a id="btn_bt_0_5" href="#">0.5秒(实时)</a></li>
  186. <li><a id="btn_bt_0_8" href="#">0.8秒(会议)</a></li>
  187. <li><a id="btn_bt_1_0" href="#">1秒(低延迟)</a></li>
  188. <li><a id="btn_bt_2_0" href="#">2秒(较低延时)</a></li>
  189. <li><a id="btn_bt_3_0" href="#">3秒(流畅播放)</a></li>
  190. <li><a id="btn_bt_4_0" href="#">4秒(流畅播放)</a></li>
  191. <li><a id="btn_bt_5_0" href="#">5秒(网速较低)</a></li>
  192. <li><a id="btn_bt_6_0" href="#">6秒(网速较低)</a></li>
  193. <li><a id="btn_bt_8_0" href="#">8秒(网速较低)</a></li>
  194. <li><a id="btn_bt_10_0" href="#">10秒(无所谓延迟)</a></li>
  195. <li><a id="btn_bt_15_0" href="#">15秒(无所谓延迟)</a></li>
  196. <li><a id="btn_bt_20_0" href="#">20秒(无所谓延迟)</a></li>
  197. <li><a id="btn_bt_30_0" href="#">30秒(流畅第一)</a></li>
  198. </ul>
  199. </div>
  200. <div class="btn-group dropup">
  201. <button class="btn dropdown-toggle" data-toggle="dropdown">最大缓冲区<span class="caret"></span></button>
  202. <ul class="dropdown-menu">
  203. <li><a id="btn_mbt_0_6" href="#">0.6秒(实时)</a></li>
  204. <li><a id="btn_mbt_0_9" href="#">0.9秒(实时)</a></li>
  205. <li><a id="btn_mbt_1_2" href="#">1.2秒(实时)</a></li>
  206. <li><a id="btn_mbt_1_5" href="#">1.5秒(实时)</a></li>
  207. <li><a id="btn_mbt_2_4" href="#">2.4秒(会议)</a></li>
  208. <li><a id="btn_mbt_3_0" href="#">3秒(低延迟)</a></li>
  209. <li><a id="btn_mbt_6_0" href="#">6秒(较低延时)</a></li>
  210. <li><a id="btn_mbt_9_0" href="#">9秒(流畅播放)</a></li>
  211. <li><a id="btn_mbt_12_0" href="#">12秒(流畅播放)</a></li>
  212. <li><a id="btn_mbt_15_0" href="#">15秒(网速较低)</a></li>
  213. <li><a id="btn_mbt_18_0" href="#">18秒(网速较低)</a></li>
  214. <li><a id="btn_mbt_24_0" href="#">24秒(网速较低)</a></li>
  215. <li><a id="btn_mbt_30_0" href="#">30秒(无所谓延迟)</a></li>
  216. <li><a id="btn_mbt_45_0" href="#">45秒(无所谓延迟)</a></li>
  217. <li><a id="btn_mbt_60_0" href="#">60秒(无所谓延迟)</a></li>
  218. <li><a id="btn_mbt_90_0" href="#">90秒(流畅第一)</a></li>
  219. </ul>
  220. </div>
  221. <div class="btn-group dropup">
  222. <a id="btn_fullscreen" class="btn">全屏</a>
  223. </div>
  224. <div class="btn-group dropup">
  225. <button id="btn_pause" class="btn">暂停播放</button>
  226. <button id="btn_resume" class="btn hide">继续播放</button>
  227. </div>
  228. <div class="btn-group dropup">
  229. <button class="btn btn-primary" data-dismiss="modal" aria-hidden="true">关闭播放器</button>
  230. </div>
  231. </div>
  232. <div class="hide" id="fullscreen_tips">
  233. 请<font color="red">点击视频</font>进入全屏模式~<br/>
  234. 由于安全原因,Flash全屏无法使用JS触发
  235. </div>
  236. <div>
  237. <div class="input-prepend div_play_time" title="BufferLength/BufferTime/MaxBufferTime">
  238. <span class="add-on">@B</span>
  239. <input class="span2" style="width:80px" id="txt_buffer" type="text" placeholder="0/0/0s">
  240. </div>
  241. <div class="input-prepend div_play_time" title="视频的播放流畅度">
  242. <span class="add-on">@F</span>
  243. <input class="span2" style="width:57px" id="txt_fluency" type="text" placeholder="100%">
  244. </div>
  245. <div class="input-prepend div_play_time" title="视频总共卡顿次数">
  246. <span class="add-on">@E</span>
  247. <input class="span2" style="width:45px" id="txt_empty_count" type="text" placeholder="0">
  248. </div>
  249. <div class="input-prepend div_play_time" title="视频当前的帧率FPS">
  250. <span class="add-on">@F</span>
  251. <input class="span2" style="width:55px" id="txt_fps" type="text" placeholder="fps">
  252. </div>
  253. <div class="input-prepend div_play_time" title="视频当前的码率(视频+音频),单位:Kbps">
  254. <span class="add-on">@B</span>
  255. <input class="span2" style="width:55px" id="txt_bitrate" type="text" placeholder="kbps">
  256. </div>
  257. <div class="input-prepend div_play_time" title="播放时长,格式:天 时:分:秒">
  258. <span class="add-on">@T</span>
  259. <input class="span2" style="width:85px" id="txt_time" type="text" placeholder="天 时:分:秒">
  260. </div>
  261. </div>
  262. <div style="margin-top:-12px;">
  263. <span id="debug_info"></span>
  264. URL: <a href="#" id="player_url"></a>
  265. <div class="input-prepend div_play_time" title="当前时间:年-月-日 时:分:秒">
  266. <span class="add-on">@N</span>
  267. <input class="span2" style="width:135px" id="player_clock" type="text" placeholder="年-月-日 时:分:秒">
  268. </div>
  269. </div>
  270. <div>
  271. <div class="input-prepend" title="首播时间,点播放到开始播放的时间,秒">
  272. <span class="add-on">@PST</span>
  273. <input class="span1" style="width:60px" id="txt_pst" type="text" placeholder="N秒">
  274. </div>
  275. </div>
  276. </div>
  277. </div>
  278. </div>
  279. <footer>
  280. <p></p>
  281. <p><a href="https://github.com/ossrs/srs">SRS Team &copy; 2013</a></p>
  282. </footer>
  283. </div>
  284. </body>
  285. <script type="text/javascript" src="js/jquery-1.12.2.min.js"></script>
  286. <script type="text/javascript" src="js/bootstrap.min.js"></script>
  287. <script type="text/javascript" src="js/swfobject.js"></script>
  288. <script type="text/javascript" src="js/json2.js"></script>
  289. <script type="text/javascript" src="js/srs.page.js"></script>
  290. <script type="text/javascript" src="js/srs.log.js"></script>
  291. <script type="text/javascript" src="js/srs.player.js"></script>
  292. <script type="text/javascript" src="js/srs.publisher.js"></script>
  293. <script type="text/javascript" src="js/srs.utility.js"></script>
  294. <script type="text/javascript" src="js/winlin.utility.js"></script>
  295. <script type="text/javascript">
  296. var __on_flash_ready = null;
  297. $(function(){
  298. // 探测Flash是否正常启用。
  299. $('#main_flash_hdr').html(
  300. '\
  301. <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="100%" height="100%"> \
  302. <param name="movie" value="srs_player/release/srs_player.swf"> \
  303. <param name="quality" value="autohigh"> \
  304. <param name="swliveconnect" value="true"> \
  305. <param name="allowScriptAccess" value="always"> \
  306. <param name="bgcolor" value="#0"> \
  307. <param name="allowFullScreen" value="true"> \
  308. <param name="wmode" value="opaque"> \
  309. <param name="FlashVars" value="log=1"> \
  310. <param name="flashvars" value="id=1&on_player_ready=__on_flash_ready"> \
  311. <embed src="srs_player/release/srs_player.swf" width="100%" height="100%" \
  312. quality="autohigh" bgcolor="#0" align="middle" allowfullscreen="true" allowscriptaccess="always" \
  313. type="application/x-shockwave-flash" swliveconnect="true" wmode="opaque" \
  314. flashvars="id=1&on_player_ready=__on_flash_ready" \
  315. pluginspage="http://www.macromedia.com/go/getflashplayer"> \
  316. </object> \
  317. '
  318. );
  319. $('#main_flash_hdr').show();
  320. var showFlashHdr = setTimeout(function(){
  321. $('#main_flash_alert').show();
  322. }, 300);
  323. __on_flash_ready = function (id) {
  324. clearTimeout(showFlashHdr);
  325. $('#main_flash_alert').hide();
  326. $('#main_flash_hdr').hide();
  327. $('#main_content').show();
  328. autoLoadPage();
  329. };
  330. });
  331. </script>
  332. <script type="text/javascript">
  333. var srs_player = null;
  334. var url = null;
  335. var __active_dar = null;
  336. function select_dar(dar_id, num, den) {
  337. srs_player.set_dar(num, den);
  338. if (__active_dar) {
  339. __active_dar.removeClass("active");
  340. }
  341. __active_dar = $(dar_id).parent();
  342. __active_dar.addClass("active");
  343. }
  344. var __active_size = null;
  345. function select_fs_size(size_id, refer, percent) {
  346. srs_player.set_fs(refer, percent);
  347. if (__active_size) {
  348. __active_size.removeClass("active");
  349. }
  350. __active_size = $(size_id).parent();
  351. __active_size.addClass("active");
  352. }
  353. function select_buffer(buffer_time) {
  354. var bt = buffer_time;
  355. var bt_id = "#btn_bt_" + bt.toFixed(1).replace(".", "_");
  356. select_buffer_time(bt_id, bt);
  357. }
  358. function select_max_buffer(max_buffer_time) {
  359. var mbt = max_buffer_time;
  360. var mbt_id = "#btn_mbt_" + mbt.toFixed(1).replace(".", "_");
  361. select_max_buffer_time(mbt_id, mbt);
  362. }
  363. var __active_bt = null;
  364. function select_buffer_time(bt_id, buffer_time) {
  365. srs_player.set_bt(buffer_time);
  366. if (__active_bt) {
  367. __active_bt.removeClass("active");
  368. }
  369. __active_bt = $(bt_id).parent();
  370. __active_bt.addClass("active");
  371. select_max_buffer(srs_player.max_buffer_time);
  372. }
  373. var __active_mbt = null;
  374. function select_max_buffer_time(mbt_id, max_buffer_time) {
  375. srs_player.set_mbt(max_buffer_time);
  376. if (__active_mbt) {
  377. __active_mbt.removeClass("active");
  378. }
  379. __active_mbt = $(mbt_id).parent();
  380. __active_mbt.addClass("active");
  381. }
  382. /****
  383. * The parameters for this page:
  384. * schema, the protocol schema, rtmp or http.
  385. * server, the ip of the url.
  386. * port, the rtmp port of url.
  387. * vhost, the vhost of url, can equals to server.
  388. * app, the app of url.
  389. * stream, the stream of url, can endwith .flv or .mp4 or nothing for RTMP.
  390. * autostart, whether auto play the stream.
  391. * buffer, the buffer time in seconds.
  392. * extra params:
  393. * shp_identify, hls+ param.
  394. * for example:
  395. * http://localhost:8088/players/srs_player.html?vhost=ossrs.net&app=live&stream=livestream&server=ossrs.net&port=1935&autostart=true&schema=rtmp
  396. * http://localhost:8088/players/srs_player.html?vhost=ossrs.net&app=live&stream=livestream.flv&server=ossrs.net&port=8080&autostart=true&schema=http
  397. */
  398. var autoLoadPage = function() {
  399. var query = parse_query_string();
  400. // get the vhost and port to set the default url.
  401. // url set to: http://localhost:8080/live/livestream.flv
  402. srs_init_flv("#txt_url", "#main_modal");
  403. // consts for buffer and max buffer.
  404. var bts = [0.1, 0.2, 0.3, 0.5, 0.8, 1, 2, 3, 4, 5, 6, 8, 10, 15, 20, 30];
  405. var mbts = [0.6, 0.9, 1.2, 1.5, 2.4, 3, 6, 9, 12, 15, 18, 24, 30, 45, 60, 90];
  406. // the play startup time.
  407. var pst = new Date();
  408. $("#main_modal").on("show", function(){
  409. if (srs_player) {
  410. return;
  411. }
  412. $("#div_container").remove();
  413. $("#debug_info").text("");
  414. var div_container = $("<div/>");
  415. $(div_container).attr("id", "div_container");
  416. $("#player").append(div_container);
  417. var player = $("<div/>");
  418. $(player).attr("id", "player_id");
  419. $(div_container).append(player);
  420. apply_url_change();
  421. srs_player = new SrsPlayer("player_id", srs_get_player_width(), srs_get_player_height());
  422. srs_player.on_player_ready = function() {
  423. var buffer_time = 0.5;
  424. if (url.indexOf('.m3u8') > 0) {
  425. buffer_time = 2;
  426. }
  427. if (query.buffer) {
  428. for (var i = 0; i < bts.length - 1; i++) {
  429. var cur = bts[i];
  430. var next = bts[i+1];
  431. if (Number(query.buffer) >= cur && Number(query.buffer) < next) {
  432. buffer_time = cur;
  433. break;
  434. }
  435. }
  436. }
  437. select_buffer(buffer_time);
  438. this.play(url);
  439. pst = new Date();
  440. };
  441. srs_player.on_player_status = function(code, desc) {
  442. //console.log("[播放器状态] code=" + code + ", desc=" + desc);
  443. };
  444. srs_player.on_player_metadata = function(metadata) {
  445. $("#btn_dar_original").text("视频原始比例" + "(" + metadata.width + ":" + metadata.height + ")");
  446. if (metadata.ip && metadata.pid && metadata.cid) {
  447. $("#debug_info").text("ID:" + metadata.ip + '/' + metadata.pid + '/' + metadata.cid + '');
  448. }
  449. select_dar("#btn_dar_original", 0, 0);
  450. select_fs_size("#btn_fs_size_screen_100", "screen", 100);
  451. };
  452. srs_player.on_player_timer = function(time, buffer_length, kbps, fps, rtime) {
  453. if (time > 0 && pst) {
  454. var diff = (new Date().getTime() - pst.getTime()) / 1000.0;
  455. $("#txt_pst").val(Number(diff).toFixed(2) + "秒");
  456. pst = null;
  457. }
  458. var buffer = buffer_length / this.max_buffer_time * 100;
  459. $("#pb_buffer").width(Number(buffer).toFixed(1) + "%");
  460. $("#pb_buffer_bg").attr("title",
  461. "缓冲区:" + buffer_length.toFixed(1) + "秒, 最大缓冲区:"
  462. + this.max_buffer_time.toFixed(1) + "秒, 当前:"
  463. + buffer.toFixed(1) + "%");
  464. var bts = this.buffer_time >= 1? this.buffer_time.toFixed(0) : this.buffer_time.toFixed(1);
  465. var mbts = this.buffer_time >= 1? this.max_buffer_time.toFixed(0) : this.max_buffer_time.toFixed(1);
  466. $("#txt_buffer").val(buffer_length.toFixed(1) + "/" + bts + "/" + mbts + "s");
  467. $("#txt_bitrate").val(kbps.toFixed(0) + "kbps");
  468. $("#txt_fps").val(fps.toFixed(1) + "fps");
  469. $("#txt_empty_count").val(srs_player.empty_count() + "次");
  470. $("#txt_fluency").val(srs_player.fluency().toFixed(2) + "%");
  471. var time_str = "";
  472. // day
  473. time_str = padding(parseInt(time / 24 / 3600), 2, '0') + " ";
  474. // hour
  475. time = time % (24 * 3600);
  476. time_str += padding(parseInt(time / 3600), 2, '0') + ":";
  477. // minute
  478. time = time % (3600);
  479. time_str += padding(parseInt(time / 60), 2, '0') + ":";
  480. // seconds
  481. time = time % (60);
  482. time_str += padding(parseInt(time), 2, '0');
  483. // show
  484. $("#txt_time").val(time_str);
  485. var clock = new Date().getTime() / 1000;
  486. $("#player_clock").val(absolute_seconds_to_YYYYmmdd(clock) + " " + absolute_seconds_to_HHMMSS(clock));
  487. };
  488. srs_player.start();
  489. });
  490. $("#main_modal").on("hide", function(){
  491. if (srs_player) {
  492. // report the log to backend.
  493. //console.log(srs_player.dump_log());
  494. srs_player.stop();
  495. srs_player = null;
  496. }
  497. });
  498. var apply_url_change = function() {
  499. var rtmp = parse_rtmp_url($("#txt_url").val());
  500. var schema = window.location.protocol;
  501. var url = schema + "//" + query.host + query.pathname + "?"
  502. + "app=" + rtmp.app + "&stream=" + rtmp.stream
  503. + "&server=" + rtmp.server + "&port=" + rtmp.port
  504. + "&autostart=true";
  505. if (query.shp_identify) {
  506. url += "&shp_identify=" + query.shp_identify;
  507. }
  508. if (rtmp.vhost === "__defaultVhost__") {
  509. url += "&vhost=" + rtmp.server;
  510. } else {
  511. url += "&vhost=" + rtmp.vhost;
  512. }
  513. if (rtmp.schema !== "rtmp") {
  514. url += "&schema=" + rtmp.schema;
  515. }
  516. if (query.buffer) {
  517. url += "&buffer=" + query.buffer;
  518. }
  519. if (query.api_port) {
  520. url += "&api_port=" + query.api_port;
  521. }
  522. var queries = user_extra_params(query);
  523. queries = user_extra_params(rtmp, queries);
  524. if (queries && queries.length) {
  525. url += '&' + queries.join('&');
  526. }
  527. $("#player_url").text($("#txt_url").val()).attr("href", url);
  528. $("#link_server").text(rtmp.server);
  529. $("#link_port").text(rtmp.port);
  530. $("#link_vhost").text(rtmp.vhost);
  531. $("#link_app").text(rtmp.app);
  532. $("#link_stream").text(rtmp.stream);
  533. $("#link_rtmp").text($("#txt_url").val());
  534. $("#link_url").attr("href", url);
  535. };
  536. $("#txt_url").change(function(){
  537. apply_url_change();
  538. });
  539. $("#btn_generate_link").click(function(){
  540. $("#link_modal").modal({show:true, keyboard:true});
  541. });
  542. $("#btn_play").click(function(){
  543. url = $("#txt_url").val();
  544. $("#main_modal").modal({show:true, keyboard:true});
  545. });
  546. $("#btn_fullscreen").click(function(){
  547. $("#fullscreen_tips").toggle();
  548. });
  549. $("#btn_pause").click(function() {
  550. $("#btn_resume").toggle();
  551. $("#btn_pause").toggle();
  552. srs_player.pause();
  553. });
  554. $("#btn_resume").click(function(){
  555. $("#btn_resume").toggle();
  556. $("#btn_pause").toggle();
  557. srs_player.resume();
  558. });
  559. if (true) {
  560. $("#srs_publish").click(function () {
  561. url = $("#srs_publish").text();
  562. $("#main_modal").modal({show: true, keyboard: false});
  563. });
  564. $("#srs_publish_ld").click(function () {
  565. url = $("#srs_publish_ld").text();
  566. $("#main_modal").modal({show: true, keyboard: false});
  567. });
  568. $("#srs_publish_sd").click(function () {
  569. url = $("#srs_publish_sd").text();
  570. $("#main_modal").modal({show: true, keyboard: false});
  571. });
  572. $("#srs_publish_fw").click(function () {
  573. url = $("#srs_publish_fw").text();
  574. $("#main_modal").modal({show: true, keyboard: false});
  575. });
  576. $("#srs_publish_fw_ld").click(function () {
  577. url = $("#srs_publish_fw_ld").text();
  578. $("#main_modal").modal({show: true, keyboard: false});
  579. });
  580. $("#srs_publish_fw_sd").click(function () {
  581. url = $("#srs_publish_fw_sd").text();
  582. $("#main_modal").modal({show: true, keyboard: false});
  583. });
  584. }
  585. if (true) {
  586. $("#btn_dar_original").click(function(){
  587. select_dar("#btn_dar_original", 0, 0);
  588. });
  589. $("#btn_dar_21_9").click(function(){
  590. select_dar("#btn_dar_21_9", 21, 9);
  591. });
  592. $("#btn_dar_16_9").click(function(){
  593. select_dar("#btn_dar_16_9", 16, 9);
  594. });
  595. $("#btn_dar_4_3").click(function(){
  596. select_dar("#btn_dar_4_3", 4, 3);
  597. });
  598. $("#btn_dar_fill").click(function(){
  599. select_dar("#btn_dar_fill", -1, -1);
  600. });
  601. }
  602. if (true) {
  603. $("#btn_fs_size_video_100").click(function(){
  604. select_fs_size("#btn_fs_size_video_100", "video", 100);
  605. });
  606. $("#btn_fs_size_video_75").click(function(){
  607. select_fs_size("#btn_fs_size_video_75", "video", 75);
  608. });
  609. $("#btn_fs_size_video_50").click(function(){
  610. select_fs_size("#btn_fs_size_video_50", "video", 50);
  611. });
  612. $("#btn_fs_size_screen_100").click(function(){
  613. select_fs_size("#btn_fs_size_screen_100", "screen", 100);
  614. });
  615. $("#btn_fs_size_screen_75").click(function(){
  616. select_fs_size("#btn_fs_size_screen_75", "screen", 75);
  617. });
  618. $("#btn_fs_size_screen_50").click(function(){
  619. select_fs_size("#btn_fs_size_screen_50", "screen", 50);
  620. });
  621. }
  622. if (true) {
  623. for (var i = 0; i < bts.length; i++) {
  624. var bt = bts[i];
  625. var bt_id = "#btn_bt_" + bt.toFixed(1).replace(".", "_");
  626. var bt_fun = function(id, v){
  627. $(bt_id).click(function(){
  628. select_buffer_time(id, v);
  629. // remember the chagned buffer.
  630. if (Number(query.buffer) != srs_player.buffer_time) {
  631. query.buffer = srs_player.buffer_time;
  632. apply_url_change();
  633. }
  634. });
  635. };
  636. bt_fun(bt_id, bt);
  637. }
  638. }
  639. if (true) {
  640. for (var i = 0; i < mbts.length; i++) {
  641. var mbt = mbts[i];
  642. var mbt_id = "#btn_mbt_" + mbt.toFixed(1).replace(".", "_");
  643. var mbt_fun = function(id, v){
  644. $(mbt_id).click(function(){
  645. select_max_buffer_time(id, v);
  646. });
  647. };
  648. mbt_fun(mbt_id, mbt);
  649. }
  650. }
  651. var query = parse_query_string();
  652. if (query.autostart == "true") {
  653. url = $("#txt_url").val();
  654. $("#main_modal").modal({show:true, keyboard:false});
  655. }
  656. apply_url_change();
  657. };
  658. </script>
  659. </html>