平安校园
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

89 rivejä
3.5 KiB

  1. <!DOCTYPE html>
  2. <html style="overflow: hidden;">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="x-ua-compatible" content="IE=edge">
  6. <meta name="viewport"
  7. content="width=device-width, height=device-height, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
  8. <title>Aliplayer Rts Demo</title>
  9. <link rel="stylesheet"
  10. href="https://g.alicdn.com/apsara-media-box/imp-web-player/2.16.3/skins/default/aliplayer-min.css" />
  11. <script type="text/javascript" charset="utf-8"
  12. src="https://g.alicdn.com/apsara-media-box/imp-web-player/2.16.3/aliplayer-min.js"></script>
  13. </head>
  14. <body style="margin: 0;">
  15. <div class="prism-player" id="player-con"></div>
  16. <script>
  17. // 使用: /static/rtsPlayer.html?rtsUrl=
  18. /**
  19. * 播放器默认播放 source 提供的 rts 拉流地址,如果失败,则会自动降级至 rtsFallbackSource 提供的拉流地址(如 HLS 地址)。
  20. * 可能的降级场景包括:
  21. * 1. 浏览器不支持 RTS,直接降级
  22. * 2. RTS 信令请求失败(拉流地址无效、https配置无效、RTS配置无效等),直接降级
  23. * 3. RTS 起播超时或中途断流,按自定义策略重试失败后降级
  24. **/
  25. // 更多播放器配置请参考 https://player.alicdn.com/aliplayer/index.html
  26. let rtsUrl = getUrlParams(location.href)['rtsUrl'] || ''
  27. let height = getUrlParams(location.href)['height'] || "500px"
  28. var options = {
  29. "id": "player-con",
  30. "source": rtsUrl,
  31. "rtsFallbackSource": "降级地址,如HLS",
  32. "width": "100%",
  33. "height": height,
  34. "autoplay": true,
  35. "isLive": true,
  36. "playsinline": true,
  37. "skipRtsSupportCheck": false, // 对于不在 https://help.aliyun.com/document_detail/397569.html 中的浏览器,可以传 true 跳过检查,强制使用 RTS(有风险,需要自测保证)
  38. /**
  39. * RTS 拉流超时会默认重试
  40. * 以下两个参数用来控制降级之前的重试策略,比如 3000 毫秒超时,重试一次,如果再拉不到流就降级,那么总共等待 6000 毫秒降级
  41. **/
  42. // RTS 多久拉不到流会重试,默认 3000 ms
  43. // rtsLoadDataTimeout: 2000,
  44. // RTS 拉不到流重试的次数,默认 5,此参数建议设为 1,即重试 1 次后降级,可以减少降级等待时间
  45. liveRetry: 1,
  46. };
  47. var player = new Aliplayer(options, function () {/* player ready */ });
  48. player.setVolume(0)
  49. // 降级时会触发此事件
  50. player.on('rtsFallback', function (event) {
  51. console.log('[EVENT]rtsFallback', event.paramData);
  52. // event.paramData.reason 降级的原因
  53. // event.paramData.fallbackUrl 降级到的地址
  54. })
  55. player.on('error', function (event) {
  56. console.log('[EVENT]error', event.paramData);
  57. })
  58. // 当RTS拉流成功时触发,通过订阅该事件,可以获取到RTS TraceId
  59. player.on('rtsTraceId', function (data) {
  60. console.log('[EVENT]rtsTraceId', data.paramData);
  61. let fullscreenBtn = document.querySelector('.prism-controlbar .prism-fullscreen-btn')
  62. if(fullscreenBtn)fullscreenBtn.style.display = 'none'
  63. // event.paramData.traceId 拉流的TraceId
  64. // event.paramData.source 当前RTS流的播放地址
  65. })
  66. function getUrlParams(url) {
  67. const reg = /(\w+)=([^&]+)/g;
  68. const params = {};
  69. let match;
  70. while ((match = reg.exec(url)) !== null) {
  71. params[match[1]] = match[2];
  72. }
  73. return params;
  74. }
  75. </script>
  76. </body>