index.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>hls.js demo</title>
  6. <link
  7. rel="stylesheet"
  8. href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.4/dist/css/bootstrap.min.css"
  9. />
  10. <link
  11. rel="stylesheet"
  12. href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.4/dist/css/bootstrap-theme.min.css"
  13. />
  14. <link rel="stylesheet" href="style.css" />
  15. <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
  16. <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.4/dist/js/bootstrap.min.js"></script>
  17. <script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.min.js"></script>
  18. <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.13.1/ace.js"></script>
  19. </head>
  20. <body>
  21. <div class="header-container">
  22. <header class="wrapper clearfix">
  23. <h1>
  24. <a target="_blank" href="https://github.com/video-dev/hls.js">
  25. <img
  26. src="https://cloud.githubusercontent.com/assets/616833/19739063/e10be95a-9bb9-11e6-8100-2896f8500138.png"
  27. />
  28. </a>
  29. </h1>
  30. <h2 class="title">demo</h2>
  31. <h3>
  32. <a href="../api-docs">API docs | usage guide</a>
  33. </h3>
  34. </header>
  35. </div>
  36. <div class="main-container">
  37. <header>
  38. <p>
  39. Test your HLS streams in all supported browsers
  40. (Chrome/Firefox/IE11/Edge/Safari).
  41. </p>
  42. <p>Advanced controls are available at the bottom of this page.</p>
  43. <p>
  44. <b
  45. >Looking for a more <i>basic</i> usage example? Go
  46. <a href="basic-usage.html">here</a>.</b
  47. ><br />
  48. </p>
  49. </header>
  50. <div id="controls">
  51. <div class="demo-controls-wrapper">
  52. <select id="streamSelect" class="innerControls">
  53. <option value="" selected>
  54. 选择或输入地址
  55. </option>
  56. </select>
  57. <input id="streamURL" class="innerControls" type="text" value="" />
  58. <label
  59. class="innerControls"
  60. title="Uncheck this to disable loading of streams selected from the drop-down above."
  61. >
  62. Enable streaming:
  63. <input id="enableStreaming" type="checkbox" checked />
  64. </label>
  65. <label
  66. class="innerControls"
  67. title="When a media error occurs, attempt to recover playback by calling `hls.recoverMediaError()`."
  68. >
  69. Auto-recover media-errors:
  70. <input id="autoRecoverError" type="checkbox" checked />
  71. </label>
  72. <label
  73. class="innerControls"
  74. title="Stop loading and playback if playback under-buffer stalls. This can help debug stall errors."
  75. >
  76. Stop on first stall:
  77. <input id="stopOnStall" type="checkbox" unchecked />
  78. </label>
  79. <label class="innerControls">
  80. Dump transmuxed fMP4 data:
  81. <input id="dumpfMP4" type="checkbox" unchecked />
  82. </label>
  83. <label class="innerControls">
  84. Metrics history (max limit, -1 is unlimited):
  85. <input id="limitMetrics" style="width: 8em" type="number" />
  86. </label>
  87. <label class="innerControls">
  88. HTML video element width:
  89. <select id="videoSize" style="float: right">
  90. <option value="240px">240px</option>
  91. <option value="426px">426px</option>
  92. <option value="640px">640px</option>
  93. <option value="720px">720px</option>
  94. <option value="854px">854px</option>
  95. <option value="1280px">1280px</option>
  96. <option value="1920px">1920px</option>
  97. <option value="80%">Responsive (80%)</option>
  98. <option value="100%">Responsive (100%)</option>
  99. </select>
  100. </label>
  101. <label class="innerControls">
  102. Current player size:
  103. <span id="currentSize"></span>
  104. </label>
  105. <label class="innerControls">
  106. Current video resolution:
  107. <span id="currentResolution"></span>
  108. </label>
  109. <label class="innerControls permalink">
  110. Permalink:&nbsp;&nbsp;<span id="StreamPermalink"></span>
  111. </label>
  112. </div>
  113. <div class="config-editor-wrapper">
  114. <div class="config-editor-container">
  115. <div id="config-editor">Loading...</div>
  116. </div>
  117. <div class="config-editor-commands">
  118. <label for="config-persistence">
  119. Persist
  120. <input
  121. name="config-persistence"
  122. id="config-persistence"
  123. type="checkbox"
  124. />
  125. </label>
  126. <button name="config-apply" onclick="applyConfigEditorValue()">
  127. Apply
  128. </button>
  129. </div>
  130. </div>
  131. </div>
  132. <video
  133. id="video"
  134. controls
  135. autoplay
  136. class="videoCentered"
  137. style="width: 80%"
  138. ></video>
  139. <br />
  140. <canvas
  141. id="bufferedCanvas"
  142. width="720"
  143. height="15"
  144. class="videoCentered"
  145. onclick="onClickBufferedRange(event);"
  146. style="height: fit-content"
  147. ></canvas>
  148. <br />
  149. <br />
  150. <label class="center">Status:</label>
  151. <pre id="statusOut" class="center" style="white-space: pre-wrap"></pre>
  152. <label class="center">Error:</label>
  153. <pre id="errorOut" class="center" style="white-space: pre-wrap"></pre>
  154. <div
  155. class="center"
  156. style="text-align: center; display: none"
  157. id="toggleButtons"
  158. >
  159. <button
  160. type="button"
  161. class="btn btn-sm demo-tab-btn"
  162. data-tab="playbackControlTab"
  163. onclick="toggleTabClick(this);"
  164. >
  165. Playback
  166. </button>
  167. <button
  168. type="button"
  169. class="btn btn-sm demo-tab-btn"
  170. data-tab="timelineTab"
  171. onclick="toggleTabClick(this);"
  172. >
  173. Timeline
  174. </button>
  175. <button
  176. type="button"
  177. class="btn btn-sm demo-tab-btn"
  178. data-tab="qualityLevelControlTab"
  179. onclick="toggleTabClick(this);"
  180. >
  181. Quality-levels
  182. </button>
  183. <button
  184. type="button"
  185. class="btn btn-sm demo-tab-btn"
  186. data-tab="audioTrackControlTab"
  187. onclick="toggleTabClick(this);"
  188. >
  189. Audio-tracks
  190. </button>
  191. <button
  192. type="button"
  193. class="btn btn-sm demo-tab-btn"
  194. data-tab="metricsDisplayTab"
  195. onclick="toggleTabClick(this); showMetrics();"
  196. >
  197. Real-time metrics
  198. </button>
  199. <button
  200. type="button"
  201. class="btn btn-sm demo-tab-btn"
  202. data-tab="statsDisplayTab"
  203. onclick="toggleTabClick(this);"
  204. >
  205. Buffer &amp; Statistics
  206. </button>
  207. </div>
  208. <div
  209. class="center demo-tab"
  210. id="playbackControlTab"
  211. style="display: none"
  212. >
  213. <br />
  214. <center>
  215. <p>
  216. <span>
  217. <button
  218. type="button"
  219. class="btn btn-sm btn-info"
  220. title="video.play()"
  221. onclick="$('#video')[0].play()"
  222. >
  223. Play
  224. </button>
  225. <button
  226. type="button"
  227. class="btn btn-sm btn-info"
  228. title="video.pause()"
  229. onclick="$('#video')[0].pause()"
  230. >
  231. Pause
  232. </button>
  233. </span>
  234. <span>
  235. <button
  236. type="button"
  237. class="btn btn-sm btn-info"
  238. title="video.playbackRate = text input"
  239. onclick="$('#video')[0].defaultPlaybackRate=$('#video')[0].playbackRate=$('#playback_rate').val();"
  240. >
  241. Playback rate
  242. </button>
  243. <input
  244. type="number"
  245. value="1"
  246. id="playback_rate"
  247. size="8"
  248. style="width: 3em"
  249. onkeydown="if(window.event.keyCode=='13'){$('#video')[0].defaultPlaybackRate=$('#video')[0].playbackRate=$('#playback_rate').val();}"
  250. />
  251. </span>
  252. <span>
  253. <button
  254. type="button"
  255. class="btn btn-sm btn-info"
  256. title="video.currentTime -= 10"
  257. onclick="$('#video')[0].currentTime-=10"
  258. >
  259. - 10 s
  260. </button>
  261. <button
  262. type="button"
  263. class="btn btn-sm btn-info"
  264. title="video.currentTime += 10"
  265. onclick="$('#video')[0].currentTime+=10"
  266. >
  267. + 10 s
  268. </button>
  269. </span>
  270. <span>
  271. <button
  272. type="button"
  273. class="btn btn-sm btn-info"
  274. title="video.currentTime = text input"
  275. onclick="$('#video')[0].currentTime=$('#seek_pos').val();"
  276. >
  277. Seek to
  278. </button>
  279. <input
  280. type="number"
  281. id="seek_pos"
  282. size="8"
  283. style="width: 7em"
  284. onkeydown="if(window.event.keyCode=='13'){$('#video')[0].currentTime=$('#seek_pos').val();}"
  285. />
  286. </span>
  287. </p>
  288. <p>
  289. <span>
  290. <button
  291. type="button"
  292. class="btn btn-xs btn-warning"
  293. title="hls.startLoad()"
  294. onclick="hls.startLoad()"
  295. >
  296. Start loading
  297. </button>
  298. <button
  299. type="button"
  300. class="btn btn-xs btn-warning"
  301. title="hls.stopLoad()"
  302. onclick="hls.stopLoad()"
  303. >
  304. Stop loading
  305. </button>
  306. </span>
  307. <span>
  308. <button
  309. type="button"
  310. class="btn btn-xs btn-warning"
  311. title="hls.attachMedia(video)"
  312. onclick="hls.attachMedia($('#video')[0])"
  313. >
  314. Attach media
  315. </button>
  316. <button
  317. type="button"
  318. class="btn btn-xs btn-warning"
  319. title="hls.detachMedia()"
  320. onclick="hls.detachMedia()"
  321. >
  322. Detach media
  323. </button>
  324. </span>
  325. </p>
  326. <p>
  327. <span>
  328. <button
  329. type="button"
  330. class="btn btn-xs btn-warning"
  331. title="hls.recoverMediaError()"
  332. onclick="hls.recoverMediaError()"
  333. >
  334. Recover media-error
  335. </button>
  336. <button
  337. type="button"
  338. class="btn btn-xs btn-warning"
  339. title="hls.swapAudioCodec()"
  340. onclick="hls.swapAudioCodec()"
  341. >
  342. Swap audio codec
  343. </button>
  344. </span>
  345. </p>
  346. <p>
  347. <span>
  348. <button
  349. type="button"
  350. class="btn btn-xs btn-default"
  351. onclick="$('#streamSelect')[0].selectedIndex++;$('#streamSelect').change()"
  352. >
  353. Next video
  354. </button>
  355. <button
  356. type="button"
  357. class="btn btn-xs btn-default btn-dump"
  358. title="Save dumped audio mp4 appends"
  359. onclick="createfMP4('audio');"
  360. >
  361. Create audio-fmp4
  362. </button>
  363. <button
  364. type="button"
  365. class="btn btn-xs btn-default btn-dump"
  366. title="Save dumped video mp4 appends"
  367. onclick="createfMP4('video')"
  368. >
  369. Create video-fmp4
  370. </button>
  371. </span>
  372. </p>
  373. </center>
  374. </div>
  375. <div
  376. class="center demo-tab demo-timeline-chart-container"
  377. id="timelineTab"
  378. style="display: none"
  379. >
  380. <canvas id="timeline-chart" style="touch-action: manipulation"></canvas>
  381. </div>
  382. <div
  383. class="center demo-tab"
  384. id="qualityLevelControlTab"
  385. style="display: none"
  386. >
  387. <center>
  388. <table>
  389. <tr>
  390. <td>
  391. <p>Currently played level:</p>
  392. </td>
  393. <td>
  394. <div id="currentLevelControl" style="display: inline"></div>
  395. </td>
  396. </tr>
  397. <tr>
  398. <td>
  399. <p>Next level loaded:</p>
  400. </td>
  401. <td>
  402. <div id="nextLevelControl" style="display: inline"></div>
  403. </td>
  404. </tr>
  405. <tr>
  406. <td>
  407. <p>Currently loaded level:</p>
  408. </td>
  409. <td>
  410. <div id="loadLevelControl" style="display: inline"></div>
  411. </td>
  412. </tr>
  413. <tr>
  414. <td>
  415. <p>Cap-limit level (maximum):</p>
  416. </td>
  417. <td>
  418. <div id="levelCappingControl" style="display: inline"></div>
  419. </td>
  420. </tr>
  421. </table>
  422. </center>
  423. </div>
  424. <div
  425. class="center demo-tab"
  426. id="audioTrackControlTab"
  427. style="display: none"
  428. >
  429. <table>
  430. <tr>
  431. <td>Current audio-track:</td>
  432. <td><div id="audioTrackControl" style="display: inline"></div></td>
  433. </tr>
  434. <tr>
  435. <td>Language / Name:</td>
  436. <td>
  437. <div id="audioTrackLabel" style="display: inline">
  438. None selected
  439. </div>
  440. </td>
  441. </tr>
  442. </table>
  443. </div>
  444. <div class="center demo-tab" id="metricsDisplayTab" style="display: none">
  445. <br />
  446. <div id="metricsButton">
  447. <button
  448. type="button"
  449. class="btn btn-xs btn-info"
  450. onclick="$('#metricsButtonWindow').toggle();$('#metricsButtonFixed').toggle();windowSliding=!windowSliding; refreshCanvas()"
  451. >
  452. toggle sliding/fixed window</button
  453. ><br />
  454. <div id="metricsButtonWindow">
  455. <button
  456. type="button"
  457. class="btn btn-xs btn-info"
  458. onclick="timeRangeSetSliding(0)"
  459. >
  460. window ALL
  461. </button>
  462. <button
  463. type="button"
  464. class="btn btn-xs btn-info"
  465. onclick="timeRangeSetSliding(2000)"
  466. >
  467. 2s
  468. </button>
  469. <button
  470. type="button"
  471. class="btn btn-xs btn-info"
  472. onclick="timeRangeSetSliding(5000)"
  473. >
  474. 5s
  475. </button>
  476. <button
  477. type="button"
  478. class="btn btn-xs btn-info"
  479. onclick="timeRangeSetSliding(10000)"
  480. >
  481. 10s
  482. </button>
  483. <button
  484. type="button"
  485. class="btn btn-xs btn-info"
  486. onclick="timeRangeSetSliding(20000)"
  487. >
  488. 20s
  489. </button>
  490. <button
  491. type="button"
  492. class="btn btn-xs btn-info"
  493. onclick="timeRangeSetSliding(30000)"
  494. >
  495. 30s
  496. </button>
  497. <button
  498. type="button"
  499. class="btn btn-xs btn-info"
  500. onclick="timeRangeSetSliding(60000)"
  501. >
  502. 60s
  503. </button>
  504. <button
  505. type="button"
  506. class="btn btn-xs btn-info"
  507. onclick="timeRangeSetSliding(120000)"
  508. >
  509. 120s</button
  510. ><br />
  511. <button
  512. type="button"
  513. class="btn btn-xs btn-info"
  514. onclick="timeRangeZoomIn()"
  515. >
  516. Window Zoom In
  517. </button>
  518. <button
  519. type="button"
  520. class="btn btn-xs btn-info"
  521. onclick="timeRangeZoomOut()"
  522. >
  523. Window Zoom Out</button
  524. ><br />
  525. <button
  526. type="button"
  527. class="btn btn-xs btn-info"
  528. onclick="timeRangeSlideLeft()"
  529. >
  530. <<< Window Slide
  531. </button>
  532. <button
  533. type="button"
  534. class="btn btn-xs btn-info"
  535. onclick="timeRangeSlideRight()"
  536. >
  537. Window Slide >>></button
  538. ><br />
  539. </div>
  540. <div id="metricsButtonFixed">
  541. <button
  542. type="button"
  543. class="btn btn-xs btn-info"
  544. onclick="windowStart=$('#windowStart').val()"
  545. >
  546. fixed window start(ms)
  547. </button>
  548. <input
  549. type="text"
  550. id="windowStart"
  551. defaultValue="0"
  552. size="8"
  553. onkeydown="if(window.event.keyCode=='13'){windowStart=$('#windowStart').val();}"
  554. />
  555. <button
  556. type="button"
  557. class="btn btn-xs btn-info"
  558. onclick="windowEnd=$('#windowEnd').val()"
  559. >
  560. fixed window end(ms)
  561. </button>
  562. <input
  563. type="text"
  564. id="windowEnd"
  565. defaultValue="10000"
  566. size="8"
  567. onkeydown="if(window.event.keyCode=='13'){windowEnd=$('#windowEnd').val();}"
  568. /><br />
  569. </div>
  570. <button
  571. type="button"
  572. class="btn btn-xs btn-success"
  573. onclick="goToMetrics()"
  574. style="font-size: 18px"
  575. >
  576. metrics link
  577. </button>
  578. <button
  579. type="button"
  580. class="btn btn-xs btn-success"
  581. onclick="goToMetricsPermaLink()"
  582. style="font-size: 18px"
  583. >
  584. metrics permalink
  585. </button>
  586. <button
  587. type="button"
  588. class="btn btn-xs btn-success"
  589. onclick="copyMetricsToClipBoard()"
  590. style="font-size: 18px"
  591. >
  592. copy metrics to clipboard
  593. </button>
  594. <canvas
  595. id="bufferTimerange_c"
  596. width="640"
  597. height="100"
  598. style="border: 1px solid #000000"
  599. onmousedown="timeRangeCanvasonMouseDown(event)"
  600. onmousemove="timeRangeCanvasonMouseMove(event)"
  601. onmouseup="timeRangeCanvasonMouseUp(event)"
  602. onmouseout="timeRangeCanvasonMouseOut(event);"
  603. ></canvas>
  604. <canvas
  605. id="bitrateTimerange_c"
  606. width="640"
  607. height="100"
  608. style="border: 1px solid #000000"
  609. ></canvas>
  610. <canvas
  611. id="bufferWindow_c"
  612. width="640"
  613. height="100"
  614. style="border: 1px solid #000000"
  615. onmousemove="windowCanvasonMouseMove(event);"
  616. ></canvas>
  617. <canvas
  618. id="videoEvent_c"
  619. width="640"
  620. height="15"
  621. style="border: 1px solid #000000"
  622. ></canvas>
  623. <canvas
  624. id="loadEvent_c"
  625. width="640"
  626. height="15"
  627. style="border: 1px solid #000000"
  628. ></canvas
  629. ><br />
  630. </div>
  631. </div>
  632. <div class="center demo-tab" id="statsDisplayTab" style="display: none">
  633. <br />
  634. <label>Buffer state:</label>
  635. <pre id="bufferedOut"></pre>
  636. <label>General stats:</label>
  637. <pre id="statisticsOut"></pre>
  638. </div>
  639. </div>
  640. <footer><br /><br /><br /><br /><br /><br /></footer>
  641. <!-- Demo page required libs -->
  642. <script src="canvas.js"></script>
  643. <script src="metrics.js"></script>
  644. <!-- demo build -->
  645. <script src="hls.js"></script>
  646. <script src="hls-demo.js"></script>
  647. </body>
  648. </html>