jessibuca.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <div ref="container" @dblclick="fullscreenSwich" style="background-color: #eee;margin:0 auto;">
  3. <div class="buttons-box" id="buttonsBox">
  4. <div class="buttons-box-left">
  5. <i v-if="!playing" class="iconfont icon-play jessibuca-btn" @click="playBtnClick"></i>
  6. <i v-if="playing" class="iconfont icon-pause jessibuca-btn" @click="pause"></i>
  7. <i class="iconfont icon-stop jessibuca-btn" @click="destroy"></i>
  8. <i v-if="isNotMute" class="iconfont icon-audio-high jessibuca-btn" @click="jessibuca.mute()"></i>
  9. <i v-if="!isNotMute" class="iconfont icon-audio-mute jessibuca-btn" @click="jessibuca.cancelMute()"></i>
  10. </div>
  11. <div class="buttons-box-right">
  12. <span class="jessibuca-btn">{{ kBps }} kb/s</span>
  13. <!-- <i class="iconfont icon-file-record1 jessibuca-btn"></i>-->
  14. <!-- <i class="iconfont icon-xiangqing2 jessibuca-btn" ></i>-->
  15. <i class="iconfont icon-camera1196054easyiconnet jessibuca-btn" @click="jessibuca.screenshot('截图','png',0.5)"
  16. style="font-size: 1rem !important"></i>
  17. <i class="iconfont icon-shuaxin11 jessibuca-btn" @click="playBtnClick"></i>
  18. <i v-if="!fullscreen" class="iconfont icon-weibiaoti10 jessibuca-btn" @click="fullscreenSwich"></i>
  19. <i v-if="fullscreen" class="iconfont icon-weibiaoti11 jessibuca-btn" @click="fullscreenSwich"></i>
  20. </div>
  21. </div>
  22. </div>
  23. </template>
  24. <script>
  25. export default {
  26. name: 'jessibuca',
  27. data() {
  28. return {
  29. jessibuca: null,
  30. playing: false,
  31. isNotMute: false,
  32. quieting: false,
  33. fullscreen: false,
  34. loaded: false, // mute
  35. speed: 0,
  36. performance: "", // 工作情况
  37. kBps: 0,
  38. btnDom: null,
  39. videoInfo: null,
  40. volume: 1,
  41. rotate: 0,
  42. vod: true, // 点播
  43. forceNoOffscreen: false,
  44. };
  45. },
  46. props: ['videoUrl', 'error', 'hasAudio', 'height'],
  47. mounted() {
  48. window.onerror = (msg) => {
  49. // console.error(msg)
  50. };
  51. let paramUrl = decodeURIComponent(this.$route.params.url)
  52. this.$nextTick(() => {
  53. this.updatePlayerDomSize()
  54. window.onresize = () => {
  55. this.updatePlayerDomSize()
  56. }
  57. if (typeof (this.videoUrl) == "undefined") {
  58. this.videoUrl = paramUrl;
  59. }
  60. this.btnDom = document.getElementById("buttonsBox");
  61. console.log("初始化时的地址为: " + this.videoUrl)
  62. this.play(this.videoUrl)
  63. })
  64. },
  65. watch: {
  66. videoUrl(newData, oldData) {
  67. this.play(newData)
  68. },
  69. immediate: true
  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. console.log("hasAudio " + this.hasAudio)
  87. this.jessibuca = new window.Jessibuca(Object.assign(
  88. {
  89. container: this.$refs.container,
  90. videoBuffer: 0.2, // 最大缓冲时长,单位秒
  91. isResize: true,
  92. decoder: "static/js/jessibuca/decoder.js",
  93. useMSE: false,
  94. showBandwidth: false,
  95. isFlv: true,
  96. // text: "WVP-PRO",
  97. // background: "static/images/zlm-logo.png",
  98. loadingText: "加载中",
  99. hasAudio: typeof (this.hasAudio) == "undefined" ? true : this.hasAudio,
  100. debug: false,
  101. supportDblclickFullscreen: false, // 是否支持屏幕的双击事件,触发全屏,取消全屏事件。
  102. operateBtns: {
  103. fullscreen: false,
  104. screenshot: false,
  105. play: false,
  106. audio: false,
  107. recorder: false,
  108. },
  109. record: "record",
  110. vod: this.vod,
  111. forceNoOffscreen: this.forceNoOffscreen,
  112. isNotMute: this.isNotMute,
  113. },
  114. options
  115. ));
  116. let _this = this;
  117. this.jessibuca.on("load", function () {
  118. console.log("on load init");
  119. });
  120. this.jessibuca.on("log", function (msg) {
  121. console.log("on log", msg);
  122. });
  123. this.jessibuca.on("record", function (msg) {
  124. console.log("on record:", msg);
  125. });
  126. this.jessibuca.on("pause", function () {
  127. _this.playing = false;
  128. });
  129. this.jessibuca.on("play", function () {
  130. _this.playing = true;
  131. });
  132. this.jessibuca.on("fullscreen", function (msg) {
  133. console.log("on fullscreen", msg);
  134. _this.fullscreen = msg
  135. });
  136. this.jessibuca.on("mute", function (msg) {
  137. console.log("on mute", msg);
  138. _this.isNotMute = !msg;
  139. });
  140. this.jessibuca.on("audioInfo", function (msg) {
  141. // console.log("audioInfo", msg);
  142. });
  143. this.jessibuca.on("videoInfo", function (msg) {
  144. // this.videoInfo = msg;
  145. console.log("videoInfo", msg);
  146. });
  147. this.jessibuca.on("bps", function (bps) {
  148. // console.log('bps', bps);
  149. });
  150. let _ts = 0;
  151. this.jessibuca.on("timeUpdate", function (ts) {
  152. // console.log('timeUpdate,old,new,timestamp', _ts, ts, ts - _ts);
  153. _ts = ts;
  154. });
  155. this.jessibuca.on("videoInfo", function (info) {
  156. console.log("videoInfo", info);
  157. });
  158. this.jessibuca.on("error", function (error) {
  159. console.log("error", error);
  160. });
  161. this.jessibuca.on("timeout", function () {
  162. console.log("timeout");
  163. });
  164. this.jessibuca.on('start', function () {
  165. console.log('start');
  166. })
  167. this.jessibuca.on("performance", function (performance) {
  168. let show = "卡顿";
  169. if (performance === 2) {
  170. show = "非常流畅";
  171. } else if (performance === 1) {
  172. show = "流畅";
  173. }
  174. _this.performance = show;
  175. });
  176. this.jessibuca.on('buffer', function (buffer) {
  177. // console.log('buffer', buffer);
  178. })
  179. this.jessibuca.on('stats', function (stats) {
  180. // console.log('stats', stats);
  181. })
  182. this.jessibuca.on('kBps', function (kBps) {
  183. _this.kBps = Math.round(kBps);
  184. });
  185. // 显示时间戳 PTS
  186. this.jessibuca.on('videoFrame', function () {
  187. })
  188. //
  189. this.jessibuca.on('metadata', function () {
  190. });
  191. },
  192. playBtnClick: function (event) {
  193. this.play(this.videoUrl)
  194. },
  195. play: function (url) {
  196. console.log(url)
  197. if (this.jessibuca) {
  198. this.destroy();
  199. }
  200. this.create();
  201. this.jessibuca.on("play", () => {
  202. this.playing = true;
  203. this.loaded = true;
  204. this.quieting = this.jessibuca.quieting;
  205. });
  206. if (this.jessibuca.hasLoaded()) {
  207. this.jessibuca.play(url);
  208. } else {
  209. this.jessibuca.on("load", () => {
  210. console.log("load 播放")
  211. this.jessibuca.play(url);
  212. });
  213. }
  214. },
  215. pause: function () {
  216. if (this.jessibuca) {
  217. this.jessibuca.pause();
  218. }
  219. this.playing = false;
  220. this.err = "";
  221. this.performance = "";
  222. },
  223. destroy: function () {
  224. if (this.jessibuca) {
  225. this.jessibuca.destroy();
  226. }
  227. if (document.getElementById("buttonsBox") == null) {
  228. this.$refs.container.appendChild(this.btnDom)
  229. }
  230. this.jessibuca = null;
  231. this.playing = false;
  232. this.err = "";
  233. this.performance = "";
  234. },
  235. eventcallbacK: function (type, message) {
  236. // console.log("player 事件回调")
  237. // console.log(type)
  238. // console.log(message)
  239. },
  240. fullscreenSwich: function () {
  241. let isFull = this.isFullscreen()
  242. this.jessibuca.setFullscreen(!isFull)
  243. this.fullscreen = !isFull;
  244. },
  245. isFullscreen: function () {
  246. return document.fullscreenElement ||
  247. document.msFullscreenElement ||
  248. document.mozFullScreenElement ||
  249. document.webkitFullscreenElement || false;
  250. }
  251. },
  252. destroyed() {
  253. if (this.jessibuca) {
  254. this.jessibuca.destroy();
  255. }
  256. this.playing = false;
  257. this.loaded = false;
  258. this.performance = "";
  259. },
  260. }
  261. </script>
  262. <style>
  263. .buttons-box {
  264. width: 100%;
  265. height: 28px;
  266. background-color: rgba(43, 51, 63, 0.7);
  267. position: absolute;
  268. display: -webkit-box;
  269. display: -ms-flexbox;
  270. display: flex;
  271. left: 0;
  272. bottom: 0;
  273. user-select: none;
  274. z-index: 10;
  275. }
  276. .jessibuca-btn {
  277. width: 20px;
  278. color: rgb(255, 255, 255);
  279. line-height: 27px;
  280. margin: 0px 10px;
  281. padding: 0px 2px;
  282. cursor: pointer;
  283. text-align: center;
  284. font-size: 0.8rem !important;
  285. }
  286. .buttons-box-right {
  287. position: absolute;
  288. right: 0;
  289. }
  290. </style>