jessibuca.vue 8.6 KB

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