jessibuca.vue 9.2 KB

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