VideoControl.vue 4.5 KB

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