jessibuca.vue 8.5 KB

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