VideoControl.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <div class="videoView">
  3. <!-- <video
  4. id="video"
  5. :src="curQue.video_list[0].url"
  6. controls
  7. :poster="curQue.img_list.length > 0 ? curQue.img_list[0].url : ''"
  8. controlslist="nodownload"
  9. disablePictureInPicture
  10. @mousemove="qxdShow = true"
  11. @mouseout="videoOut"
  12. ></video>
  13. <div :class="['qxd', qxdShow ? 'qxdshow' : 'qxdhide']">清晰度</div> -->
  14. <div :id="'videoPlayer' + indexStr" @mousemove="viedeoMove"></div>
  15. </div>
  16. </template>
  17. <script>
  18. //这里可以导入其它文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  19. //例如:import 《组件名称》from ‘《组件路径》';
  20. import vedioPlayer from "xgplayer";
  21. import "video.js/dist/video-js.css";
  22. export default {
  23. //import引入的组件需要注入到对象中才能使用
  24. components: {},
  25. props: ["curQue", "fn_data", "type", "indexStr"],
  26. data() {
  27. //这里存放数据
  28. return {
  29. qxdShow: true,
  30. VideoStatus: "",
  31. player: null,
  32. };
  33. },
  34. //计算属性 类似于data概念
  35. computed: {},
  36. //监控data中数据变化
  37. watch: {
  38. player: {
  39. handler: function () {
  40. //do something
  41. // if (this.player._hasStart) {
  42. //this.zantingAudio()
  43. // }
  44. this.player.once("play", () => {
  45. this.zantingAudio();
  46. });
  47. },
  48. deep: true,
  49. },
  50. },
  51. //方法集合
  52. methods: {
  53. zantingAudio() {
  54. let audio = document.getElementsByTagName("audio");
  55. audio.forEach((item) => {
  56. item.pause();
  57. });
  58. },
  59. // videoOut() {
  60. // if (this.VideoStatus == "播放") {
  61. // this.qxdShow = false;
  62. // }
  63. // },
  64. viedeoMove() {
  65. let name = document.getElementsByClassName("name")[0];
  66. if (name) {
  67. let text = name.innerText || name.textContent;
  68. if (!text) {
  69. name.innerText
  70. ? (name.innerText = "流畅")
  71. : (name.textContent = "流畅");
  72. }
  73. }
  74. },
  75. videoClick() {
  76. if (this.player._hasStart) {
  77. this.zantingAudio();
  78. }
  79. },
  80. },
  81. //生命周期 - 创建完成(可以访问当前this实例)
  82. created() {},
  83. //生命周期 - 挂载完成(可以访问DOM元素)
  84. mounted() {
  85. let _this = this;
  86. // let node = document.getElementById("video");
  87. // node.addEventListener("playing", function () {
  88. // //播放中
  89. // _this.VideoStatus = "播放";
  90. // });
  91. // node.addEventListener("pause", function () {
  92. // //暂停开始执行的函数
  93. // _this.VideoStatus = "暂停";
  94. // });
  95. _this.player = new vedioPlayer({
  96. id: `videoPlayer${_this.indexStr}`,
  97. autoplay: false,
  98. volume: 0.5, //视频初始音量大小
  99. loop: false, //是否循环播放
  100. url: _this.curQue.definition_list[0].file_url,
  101. poster:
  102. _this.curQue.img_list.length > 0 ? _this.curQue.img_list[0].url : "", //视频封面
  103. height: "100%",
  104. width: "100%",
  105. });
  106. // 设置清晰度
  107. _this.player.emit("resourceReady", [
  108. { name: "高清", url: _this.curQue.video_list[0].url },
  109. { name: "标清", url: _this.curQue.definition_list[1].file_url },
  110. { name: "流畅", url: _this.curQue.definition_list[0].file_url },
  111. ]);
  112. setTimeout(() => {
  113. let name = document.getElementsByClassName("name")[0];
  114. if (name) {
  115. let text = name.innerText || name.textContent;
  116. if (!text) {
  117. name.innerText
  118. ? (name.innerText = "流畅")
  119. : (name.textContent = "流畅");
  120. }
  121. }
  122. }, 200);
  123. },
  124. //生命周期-创建之前
  125. beforeCreated() {},
  126. //生命周期-挂载之前
  127. beforeMount() {},
  128. //生命周期-更新之前
  129. beforUpdate() {},
  130. //生命周期-更新之后
  131. updated() {},
  132. //生命周期-销毁之前
  133. beforeDestory() {},
  134. //生命周期-销毁完成
  135. destoryed() {},
  136. //如果页面有keep-alive缓存功能,这个函数会触发
  137. activated() {},
  138. };
  139. </script>
  140. <style lang="scss" scoped>
  141. /* @import url(); 引入css类 */
  142. .videoView {
  143. width: 780px;
  144. height: 398px;
  145. padding: 16px;
  146. background: #ffffff;
  147. border: 1px solid rgba(0, 0, 0, 0.1);
  148. box-sizing: border-box;
  149. border-radius: 8px;
  150. position: relative;
  151. margin-bottom: 24px;
  152. video {
  153. width: 100%;
  154. height: 100%;
  155. object-fit: fill; //将视频标签填充整个元素
  156. border-radius: 8px;
  157. cursor: pointer;
  158. }
  159. .qxd {
  160. bottom: 55px;
  161. right: 163px;
  162. position: absolute;
  163. color: white;
  164. z-index: 999;
  165. transition: all 1s;
  166. cursor: pointer;
  167. }
  168. .qxdshow {
  169. opacity: 1;
  170. }
  171. .qxdhide {
  172. opacity: 0;
  173. }
  174. }
  175. </style>