jessibuca.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <div ref="container" @dblclick="fullscreenSwich"
  3. style="width:100%;height:100%;background-color: #000000;margin:0 auto;">
  4. <div class="buttons-box" id="buttonsBox">
  5. <div class="buttons-box-left">
  6. <i v-if="!playing" class="iconfont icon-play jessibuca-btn" @click="playBtnClick"></i>
  7. <i v-if="playing" class="iconfont icon-pause jessibuca-btn" @click="pause"></i>
  8. <i class="iconfont icon-stop jessibuca-btn" @click="destroy"></i>
  9. <i v-if="isNotMute" class="iconfont icon-audio-high jessibuca-btn" @click="mute()"></i>
  10. <i v-if="!isNotMute" class="iconfont icon-audio-mute jessibuca-btn" @click="cancelMute()"></i>
  11. </div>
  12. <div class="buttons-box-right">
  13. <span class="jessibuca-btn">{{ kBps }} kb/s</span>
  14. <!-- <i class="iconfont icon-file-record1 jessibuca-btn"></i>-->
  15. <!-- <i class="iconfont icon-xiangqing2 jessibuca-btn" ></i>-->
  16. <i class="iconfont icon-camera1196054easyiconnet jessibuca-btn" @click="screenshot"
  17. style="font-size: 1rem !important"></i>
  18. <i class="iconfont icon-shuaxin11 jessibuca-btn" @click="playBtnClick"></i>
  19. <i v-if="!fullscreen" class="iconfont icon-weibiaoti10 jessibuca-btn" @click="fullscreenSwich"></i>
  20. <i v-if="fullscreen" class="iconfont icon-weibiaoti11 jessibuca-btn" @click="fullscreenSwich"></i>
  21. </div>
  22. </div>
  23. </div>
  24. </template>
  25. <script>
  26. let jessibucaPlayer = {};
  27. export default {
  28. name: 'jessibuca',
  29. data() {
  30. return {
  31. playing: false,
  32. isNotMute: false,
  33. quieting: false,
  34. fullscreen: false,
  35. loaded: false, // mute
  36. speed: 0,
  37. performance: "", // 工作情况
  38. kBps: 0,
  39. btnDom: null,
  40. videoInfo: null,
  41. volume: 1,
  42. rotate: 0,
  43. vod: true, // 点播
  44. forceNoOffscreen: false,
  45. };
  46. },
  47. props: ['videoUrl', 'error', 'hasAudio', 'height'],
  48. mounted() {
  49. let paramUrl = decodeURIComponent(this.$route.params.url)
  50. this.$nextTick(() => {
  51. this.updatePlayerDomSize()
  52. window.onresize = () => {
  53. this.updatePlayerDomSize()
  54. }
  55. if (typeof (this.videoUrl) == "undefined") {
  56. this.videoUrl = paramUrl;
  57. }
  58. this.btnDom = document.getElementById("buttonsBox");
  59. })
  60. },
  61. watch: {
  62. videoUrl(val, _) {
  63. this.play(val);
  64. }
  65. },
  66. methods: {
  67. updatePlayerDomSize() {
  68. let dom = this.$refs.container;
  69. let width = dom.parentNode.clientWidth
  70. let height = (9 / 16) * width
  71. const clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight)
  72. if (height > clientHeight) {
  73. height = clientHeight
  74. width = (16 / 9) * height
  75. }
  76. dom.style.width = width + 'px';
  77. dom.style.height = height + "px";
  78. },
  79. create() {
  80. let options = {
  81. container: this.$refs.container,
  82. autoWasm: true,
  83. background: "",
  84. controlAutoHide: false,
  85. debug: false,
  86. decoder: "static/js/jessibuca/decoder.js",
  87. forceNoOffscreen: false,
  88. hasAudio: typeof (this.hasAudio) == "undefined" ? true : this.hasAudio,
  89. heartTimeout: 5,
  90. heartTimeoutReplay: true,
  91. heartTimeoutReplayTimes: 3,
  92. hiddenAutoPause: false,
  93. hotKey: true,
  94. isFlv: false,
  95. isFullResize: false,
  96. isNotMute: this.isNotMute,
  97. isResize: false,
  98. keepScreenOn: true,
  99. loadingText: "请稍等, 视频加载中......",
  100. loadingTimeout: 10,
  101. loadingTimeoutReplay: true,
  102. loadingTimeoutReplayTimes: 3,
  103. openWebglAlignment: false,
  104. operateBtns: {
  105. fullscreen: false,
  106. screenshot: false,
  107. play: false,
  108. audio: false,
  109. record: false
  110. },
  111. recordType: "mp4",
  112. rotate: 0,
  113. showBandwidth: false,
  114. supportDblclickFullscreen: false,
  115. timeout: 10,
  116. useMSE: true,
  117. useWCS: location.hostname === "localhost" || location.protocol === "https:",
  118. useWebFullScreen: true,
  119. videoBuffer: 0.1,
  120. wasmDecodeErrorReplay: true,
  121. wcsUseVideoRender: true
  122. };
  123. console.log("Jessibuca -> options: ", options);
  124. jessibucaPlayer[this._uid] = new window.Jessibuca({...options});
  125. let jessibuca = jessibucaPlayer[this._uid];
  126. let _this = this;
  127. jessibuca.on("pause", function () {
  128. _this.playing = false;
  129. });
  130. jessibuca.on("play", function () {
  131. _this.playing = true;
  132. });
  133. jessibuca.on("fullscreen", function (msg) {
  134. _this.fullscreen = msg
  135. });
  136. jessibuca.on("mute", function (msg) {
  137. _this.isNotMute = !msg;
  138. });
  139. jessibuca.on("performance", function (performance) {
  140. let show = "卡顿";
  141. if (performance === 2) {
  142. show = "非常流畅";
  143. } else if (performance === 1) {
  144. show = "流畅";
  145. }
  146. _this.performance = show;
  147. });
  148. jessibuca.on('kBps', function (kBps) {
  149. _this.kBps = Math.round(kBps);
  150. });
  151. jessibuca.on("videoInfo", function (msg) {
  152. console.log("Jessibuca -> videoInfo: ", msg);
  153. });
  154. jessibuca.on("audioInfo", function (msg) {
  155. console.log("Jessibuca -> audioInfo: ", msg);
  156. });
  157. jessibuca.on("error", function (msg) {
  158. console.log("Jessibuca -> error: ", msg);
  159. });
  160. jessibuca.on("timeout", function (msg) {
  161. console.log("Jessibuca -> timeout: ", msg);
  162. });
  163. jessibuca.on("loadingTimeout", function (msg) {
  164. console.log("Jessibuca -> timeout: ", msg);
  165. });
  166. jessibuca.on("delayTimeout", function (msg) {
  167. console.log("Jessibuca -> timeout: ", msg);
  168. });
  169. jessibuca.on("playToRenderTimes", function (msg) {
  170. console.log("Jessibuca -> playToRenderTimes: ", msg);
  171. });
  172. },
  173. playBtnClick: function (event) {
  174. this.play(this.videoUrl)
  175. },
  176. play: function (url) {
  177. console.log("Jessibuca -> url: ", url);
  178. if (jessibucaPlayer[this._uid]) {
  179. this.destroy();
  180. }
  181. this.create();
  182. jessibucaPlayer[this._uid].on("play", () => {
  183. this.playing = true;
  184. this.loaded = true;
  185. this.quieting = jessibuca.quieting;
  186. });
  187. if (jessibucaPlayer[this._uid].hasLoaded()) {
  188. jessibucaPlayer[this._uid].play(url);
  189. } else {
  190. jessibucaPlayer[this._uid].on("load", () => {
  191. jessibucaPlayer[this._uid].play(url);
  192. });
  193. }
  194. },
  195. pause: function () {
  196. if (jessibucaPlayer[this._uid]) {
  197. jessibucaPlayer[this._uid].pause();
  198. }
  199. this.playing = false;
  200. this.err = "";
  201. this.performance = "";
  202. },
  203. screenshot: function () {
  204. if (jessibucaPlayer[this._uid]) {
  205. jessibucaPlayer[this._uid].screenshot();
  206. }
  207. },
  208. mute: function () {
  209. if (jessibucaPlayer[this._uid]) {
  210. jessibucaPlayer[this._uid].mute();
  211. }
  212. },
  213. cancelMute: function () {
  214. if (jessibucaPlayer[this._uid]) {
  215. jessibucaPlayer[this._uid].cancelMute();
  216. }
  217. },
  218. destroy: function () {
  219. if (jessibucaPlayer[this._uid]) {
  220. jessibucaPlayer[this._uid].destroy();
  221. }
  222. if (document.getElementById("buttonsBox") == null) {
  223. this.$refs.container.appendChild(this.btnDom)
  224. }
  225. jessibucaPlayer[this._uid] = null;
  226. this.playing = false;
  227. this.err = "";
  228. this.performance = "";
  229. },
  230. fullscreenSwich: function () {
  231. let isFull = this.isFullscreen()
  232. jessibucaPlayer[this._uid].setFullscreen(!isFull)
  233. this.fullscreen = !isFull;
  234. },
  235. isFullscreen: function () {
  236. return document.fullscreenElement ||
  237. document.msFullscreenElement ||
  238. document.mozFullScreenElement ||
  239. document.webkitFullscreenElement || false;
  240. }
  241. },
  242. destroyed() {
  243. if (jessibucaPlayer[this._uid]) {
  244. jessibucaPlayer[this._uid].destroy();
  245. }
  246. this.playing = false;
  247. this.loaded = false;
  248. this.performance = "";
  249. },
  250. }
  251. </script>
  252. <style>
  253. .buttons-box {
  254. width: 100%;
  255. height: 28px;
  256. background-color: rgba(43, 51, 63, 0.7);
  257. position: absolute;
  258. display: -webkit-box;
  259. display: -ms-flexbox;
  260. display: flex;
  261. left: 0;
  262. bottom: 0;
  263. user-select: none;
  264. z-index: 10;
  265. }
  266. .jessibuca-btn {
  267. width: 20px;
  268. color: rgb(255, 255, 255);
  269. line-height: 27px;
  270. margin: 0px 10px;
  271. padding: 0px 2px;
  272. cursor: pointer;
  273. text-align: center;
  274. font-size: 0.8rem !important;
  275. }
  276. .buttons-box-right {
  277. position: absolute;
  278. right: 0;
  279. }
  280. </style>