jessibuca.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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. window.onerror = (msg) => {
  50. // console.error(msg)
  51. };
  52. console.log(this._uid)
  53. let paramUrl = decodeURIComponent(this.$route.params.url)
  54. this.$nextTick(() => {
  55. this.updatePlayerDomSize()
  56. window.onresize = () => {
  57. this.updatePlayerDomSize()
  58. }
  59. if (typeof (this.videoUrl) == "undefined") {
  60. this.videoUrl = paramUrl;
  61. }
  62. this.btnDom = document.getElementById("buttonsBox");
  63. console.log("初始化时的地址为: " + this.videoUrl)
  64. this.play(this.videoUrl)
  65. })
  66. },
  67. watch: {
  68. videoUrl(newData, oldData) {
  69. this.play(newData)
  70. },
  71. immediate: true
  72. },
  73. methods: {
  74. updatePlayerDomSize() {
  75. let dom = this.$refs.container;
  76. let width = dom.parentNode.clientWidth
  77. let height = (9 / 16) * width
  78. const clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight)
  79. if (height > clientHeight) {
  80. height = clientHeight
  81. width = (16 / 9) * height
  82. }
  83. dom.style.width = width + 'px';
  84. dom.style.height = height + "px";
  85. },
  86. create() {
  87. let options = {};
  88. console.log("hasAudio " + this.hasAudio)
  89. jessibucaPlayer[this._uid] = new window.Jessibuca(Object.assign(
  90. {
  91. container: this.$refs.container,
  92. autoWasm: true,
  93. background: "",
  94. controlAutoHide: false,
  95. debug: false,
  96. decoder: "static/js/jessibuca/decoder.js",
  97. forceNoOffscreen: true,
  98. hasAudio: typeof (this.hasAudio) == "undefined" ? true : this.hasAudio,
  99. hasVideo: true,
  100. heartTimeout: 5,
  101. heartTimeoutReplay: true,
  102. heartTimeoutReplayTimes: 3,
  103. hiddenAutoPause: false,
  104. hotKey: false,
  105. isFlv: false,
  106. isFullResize: false,
  107. isNotMute: this.isNotMute,
  108. isResize: false,
  109. keepScreenOn: false,
  110. loadingText: "请稍等, 视频加载中......",
  111. loadingTimeout: 10,
  112. loadingTimeoutReplay: true,
  113. loadingTimeoutReplayTimes: 3,
  114. openWebglAlignment: false,
  115. operateBtns: {
  116. fullscreen: false,
  117. screenshot: false,
  118. play: false,
  119. audio: false,
  120. record: false
  121. },
  122. recordType: "webm",
  123. rotate: 0,
  124. showBandwidth: false,
  125. supportDblclickFullscreen: false,
  126. timeout: 10,
  127. useMSE: location.hostname !== "localhost" && location.protocol !== "https:",
  128. useOffscreen: false,
  129. useWCS: location.hostname === "localhost" || location.protocol === "https",
  130. useWebFullScreen: false,
  131. videoBuffer: 0,
  132. wasmDecodeAudioSyncVideo: true,
  133. wasmDecodeErrorReplay: true,
  134. wcsUseVideoRender: true
  135. },
  136. options
  137. ));
  138. let jessibuca = jessibucaPlayer[this._uid];
  139. let _this = this;
  140. jessibuca.on("load", function () {
  141. console.log("on load init");
  142. });
  143. jessibuca.on("log", function (msg) {
  144. console.log("on log", msg);
  145. });
  146. jessibuca.on("record", function (msg) {
  147. console.log("on record:", msg);
  148. });
  149. jessibuca.on("pause", function () {
  150. _this.playing = false;
  151. });
  152. jessibuca.on("play", function () {
  153. _this.playing = true;
  154. });
  155. jessibuca.on("fullscreen", function (msg) {
  156. console.log("on fullscreen", msg);
  157. _this.fullscreen = msg
  158. });
  159. jessibuca.on("mute", function (msg) {
  160. console.log("on mute", msg);
  161. _this.isNotMute = !msg;
  162. });
  163. jessibuca.on("audioInfo", function (msg) {
  164. // console.log("audioInfo", msg);
  165. });
  166. jessibuca.on("videoInfo", function (msg) {
  167. // this.videoInfo = msg;
  168. console.log("videoInfo", msg);
  169. });
  170. jessibuca.on("bps", function (bps) {
  171. // console.log('bps', bps);
  172. });
  173. let _ts = 0;
  174. jessibuca.on("timeUpdate", function (ts) {
  175. // console.log('timeUpdate,old,new,timestamp', _ts, ts, ts - _ts);
  176. _ts = ts;
  177. });
  178. jessibuca.on("videoInfo", function (info) {
  179. console.log("videoInfo", info);
  180. });
  181. jessibuca.on("error", function (error) {
  182. console.log("error", error);
  183. });
  184. jessibuca.on("timeout", function () {
  185. console.log("timeout");
  186. });
  187. jessibuca.on('start', function () {
  188. console.log('start');
  189. })
  190. jessibuca.on("performance", function (performance) {
  191. let show = "卡顿";
  192. if (performance === 2) {
  193. show = "非常流畅";
  194. } else if (performance === 1) {
  195. show = "流畅";
  196. }
  197. _this.performance = show;
  198. });
  199. jessibuca.on('buffer', function (buffer) {
  200. // console.log('buffer', buffer);
  201. })
  202. jessibuca.on('stats', function (stats) {
  203. // console.log('stats', stats);
  204. })
  205. jessibuca.on('kBps', function (kBps) {
  206. _this.kBps = Math.round(kBps);
  207. });
  208. // 显示时间戳 PTS
  209. jessibuca.on('videoFrame', function () {
  210. })
  211. //
  212. jessibuca.on('metadata', function () {
  213. });
  214. },
  215. playBtnClick: function (event) {
  216. this.play(this.videoUrl)
  217. },
  218. play: function (url) {
  219. console.log(url)
  220. if (jessibucaPlayer[this._uid]) {
  221. this.destroy();
  222. }
  223. this.create();
  224. jessibucaPlayer[this._uid].on("play", () => {
  225. this.playing = true;
  226. this.loaded = true;
  227. this.quieting = jessibuca.quieting;
  228. });
  229. if (jessibucaPlayer[this._uid].hasLoaded()) {
  230. jessibucaPlayer[this._uid].play(url);
  231. } else {
  232. jessibucaPlayer[this._uid].on("load", () => {
  233. console.log("load 播放")
  234. jessibucaPlayer[this._uid].play(url);
  235. });
  236. }
  237. },
  238. pause: function () {
  239. if (jessibucaPlayer[this._uid]) {
  240. jessibucaPlayer[this._uid].pause();
  241. }
  242. this.playing = false;
  243. this.err = "";
  244. this.performance = "";
  245. },
  246. screenshot: function () {
  247. if (jessibucaPlayer[this._uid]) {
  248. jessibucaPlayer[this._uid].screenshot();
  249. }
  250. },
  251. mute: function () {
  252. if (jessibucaPlayer[this._uid]) {
  253. jessibucaPlayer[this._uid].mute();
  254. }
  255. },
  256. cancelMute: function () {
  257. if (jessibucaPlayer[this._uid]) {
  258. jessibucaPlayer[this._uid].cancelMute();
  259. }
  260. },
  261. destroy: function () {
  262. if (jessibucaPlayer[this._uid]) {
  263. jessibucaPlayer[this._uid].destroy();
  264. }
  265. if (document.getElementById("buttonsBox") == null) {
  266. this.$refs.container.appendChild(this.btnDom)
  267. }
  268. jessibucaPlayer[this._uid] = null;
  269. this.playing = false;
  270. this.err = "";
  271. this.performance = "";
  272. },
  273. eventcallbacK: function (type, message) {
  274. // console.log("player 事件回调")
  275. // console.log(type)
  276. // console.log(message)
  277. },
  278. fullscreenSwich: function () {
  279. let isFull = this.isFullscreen()
  280. jessibucaPlayer[this._uid].setFullscreen(!isFull)
  281. this.fullscreen = !isFull;
  282. },
  283. isFullscreen: function () {
  284. return document.fullscreenElement ||
  285. document.msFullscreenElement ||
  286. document.mozFullScreenElement ||
  287. document.webkitFullscreenElement || false;
  288. }
  289. },
  290. destroyed() {
  291. if (jessibucaPlayer[this._uid]) {
  292. jessibucaPlayer[this._uid].destroy();
  293. }
  294. this.playing = false;
  295. this.loaded = false;
  296. this.performance = "";
  297. },
  298. }
  299. </script>
  300. <style>
  301. .buttons-box {
  302. width: 100%;
  303. height: 28px;
  304. background-color: rgba(43, 51, 63, 0.7);
  305. position: absolute;
  306. display: -webkit-box;
  307. display: -ms-flexbox;
  308. display: flex;
  309. left: 0;
  310. bottom: 0;
  311. user-select: none;
  312. z-index: 10;
  313. }
  314. .jessibuca-btn {
  315. width: 20px;
  316. color: rgb(255, 255, 255);
  317. line-height: 27px;
  318. margin: 0px 10px;
  319. padding: 0px 2px;
  320. cursor: pointer;
  321. text-align: center;
  322. font-size: 0.8rem !important;
  323. }
  324. .buttons-box-right {
  325. position: absolute;
  326. right: 0;
  327. }
  328. </style>