demo.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. <script src="./jessibuca.js"></script>
  7. <style>
  8. .root {
  9. display: flex;
  10. place-content: center;
  11. margin-top: 3rem;
  12. }
  13. .container-shell {
  14. backdrop-filter: blur(5px);
  15. background: hsla(0, 0%, 50%, 0.5);
  16. padding: 30px 4px 10px 4px;
  17. /* border: 2px solid black; */
  18. width: auto;
  19. position: relative;
  20. border-radius: 5px;
  21. box-shadow: 0 10px 20px;
  22. }
  23. .container-shell:before {
  24. content: "jessibuca demo player";
  25. position: absolute;
  26. color: darkgray;
  27. top: 4px;
  28. left: 10px;
  29. text-shadow: 1px 1px black;
  30. }
  31. #container {
  32. background: rgba(13, 14, 27, 0.7);
  33. width: 640px;
  34. height: 398px;
  35. }
  36. .input {
  37. display: flex;
  38. margin-top: 10px;
  39. color: white;
  40. place-content: stretch;
  41. }
  42. .input2 {
  43. bottom: 0px;
  44. }
  45. .input input {
  46. flex: auto;
  47. }
  48. .err {
  49. position: absolute;
  50. top: 40px;
  51. left: 10px;
  52. color: red;
  53. }
  54. .option {
  55. position: absolute;
  56. top: 4px;
  57. right: 10px;
  58. display: flex;
  59. place-content: center;
  60. font-size: 12px;
  61. }
  62. .option span {
  63. color: white;
  64. }
  65. .page {
  66. background: url('./bg.jpg');
  67. background-repeat: no-repeat;
  68. background-position: top;
  69. }
  70. @media (max-width: 720px) {
  71. #container {
  72. width: 90vw;
  73. height: 52.7vw;
  74. }
  75. }
  76. </style>
  77. </head>
  78. <body class="page">
  79. <div class="root">
  80. <div class="container-shell">
  81. <div id="container"></div>
  82. <div class="input">
  83. <div>输入URL:</div>
  84. <input
  85. autocomplete="on"
  86. id="playUrl"
  87. value=""
  88. />
  89. <button id="play">播放</button>
  90. <button id="pause" style="display: none">停止</button>
  91. </div>
  92. <div class="input" style="line-height: 30px">
  93. <button id="destroy">销毁</button>
  94. </div>
  95. </div>
  96. </div>
  97. <script>
  98. var $player = document.getElementById('play');
  99. var $pause = document.getElementById('pause');
  100. var $playHref = document.getElementById('playUrl');
  101. var $container = document.getElementById('container');
  102. var $destroy = document.getElementById('destroy');
  103. var showOperateBtns = false; // 是否显示按钮
  104. var forceNoOffscreen = true; //
  105. var jessibuca = null;
  106. function create() {
  107. jessibuca = null;
  108. jessibuca = new Jessibuca({
  109. container: $container,
  110. videoBuffer: 0.2, // 缓存时长
  111. isResize: false,
  112. text: "",
  113. loadingText: "",
  114. useMSE: false,
  115. debug: true,
  116. showBandwidth: showOperateBtns, // 显示网速
  117. operateBtns: {
  118. fullscreen: showOperateBtns,
  119. screenshot: showOperateBtns,
  120. play: showOperateBtns,
  121. audio: false,
  122. recorder: false
  123. },
  124. forceNoOffscreen: forceNoOffscreen,
  125. isNotMute: false,
  126. },);
  127. jessibuca.on('audioInfo', function (audioInfo) {
  128. console.log('audioInfo',audioInfo);
  129. })
  130. jessibuca.on('videoInfo', function (videoInfo) {
  131. console.log('videoInfo',videoInfo);
  132. })
  133. $player.style.display = 'inline-block';
  134. $pause.style.display = 'none';
  135. $destroy.style.display = 'none';
  136. }
  137. create();
  138. $player.addEventListener('click', function () {
  139. var href = $playHref.value;
  140. if (href) {
  141. jessibuca.play(href);
  142. $player.style.display = 'none';
  143. $pause.style.display = 'inline-block';
  144. $destroy.style.display = 'inline-block';
  145. }
  146. }, false)
  147. $pause.addEventListener('click', function () {
  148. $player.style.display = 'inline-block';
  149. $pause.style.display = 'none';
  150. jessibuca.pause();
  151. })
  152. $destroy.addEventListener('click', function () {
  153. if (jessibuca) {
  154. jessibuca.destroy().then(()=>{
  155. create();
  156. });
  157. }
  158. else {
  159. create();
  160. }
  161. })
  162. </script>
  163. </body>
  164. </html>