cl-video.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <video
  3. class="cl-video"
  4. id="video"
  5. :src="src"
  6. :autoplay="autoplay"
  7. :loop="loop"
  8. :muted="muted"
  9. :initial-time="initialTime"
  10. :duration="duration"
  11. :controls="controls"
  12. :danmu-list="danmuList"
  13. :danmu-btn="danmuBtn"
  14. :enable-danmu="enableDanmu"
  15. :page-gesture="pageGesture"
  16. :direction="direction"
  17. :show-progress="showProgress"
  18. :show-fullscreen-btn="showFullscreenBtn"
  19. :show-play-btn="showPlayBtn"
  20. :show-center-play-btn="showCenterPlayBtn"
  21. :show-loading="showLoading"
  22. :enable-progress-gesture="enableProgressGesture"
  23. :object-fit="objectFit"
  24. :poster="poster"
  25. :show-mute-btn="showMuteBtn"
  26. :title="title"
  27. :play-btn-position="playBtnPosition"
  28. :enable-play-gesture="enablePlayGesture"
  29. :auto-pause-if-navigate="autoPauseIfNavigate"
  30. :auto-pause-if-open-native="autoPauseIfOpenNative"
  31. :vslide-gesture="vslideGesture"
  32. :vslide-gesture-in-fullscreen="vslideGestureInFullscreen"
  33. :ad-unit-id="adUnitId"
  34. :poster-for-crawler="posterForCrawler"
  35. @play="onPlay"
  36. @pause="onPause"
  37. @ended="onEnded"
  38. @timeupdate="onTimeUpdate"
  39. @waiting="onWaiting"
  40. @error="onError2"
  41. @progress="onProgress"
  42. @loadedmetadata="onLoadedMetaData"
  43. @fullscreenclick="onFullScreenClick"
  44. @controlstoggle="onControlStoggle"
  45. ></video>
  46. </template>
  47. <script>
  48. export default {
  49. name: "cl-video",
  50. props: {
  51. src: String,
  52. autoplay: Boolean,
  53. loop: Boolean,
  54. muted: Boolean,
  55. initialTime: Number,
  56. duration: Number,
  57. controls: {
  58. type: Boolean,
  59. default: true
  60. },
  61. danmuList: [Object, Array],
  62. danmuBtn: Boolean,
  63. enableDanmu: Boolean,
  64. pageGesture: Boolean,
  65. direction: Number,
  66. showProgress: {
  67. type: Boolean,
  68. default: true
  69. },
  70. showPlayBtn: {
  71. type: Boolean,
  72. default: true
  73. },
  74. showCenterPlayBtn: {
  75. type: Boolean,
  76. default: true
  77. },
  78. showLoading: {
  79. type: Boolean,
  80. default: true
  81. },
  82. showFullscreenBtn: {
  83. type: Boolean,
  84. default: true
  85. },
  86. enableProgressGesture: {
  87. type: Boolean,
  88. default: true
  89. },
  90. objectFit: {
  91. type: String,
  92. default: "contain"
  93. },
  94. poster: String,
  95. showMuteBtn: Boolean,
  96. title: String,
  97. playBtnPosition: {
  98. type: String,
  99. default: "bottom"
  100. },
  101. enablePlayGesture: Boolean,
  102. autoPauseIfNavigate: {
  103. type: Boolean,
  104. default: true
  105. },
  106. autoPauseIfOpenNative: {
  107. type: Boolean,
  108. default: true
  109. },
  110. vslideGesture: Boolean,
  111. vslideGestureInFullscreen: {
  112. type: Boolean,
  113. default: true
  114. },
  115. adUnitId: String,
  116. posterForCrawler: String
  117. },
  118. watch: {
  119. src: {
  120. immediate: true,
  121. handler(val) {
  122. if (val) {
  123. this.ctx = uni.createVideoContext("video", this);
  124. }
  125. }
  126. }
  127. },
  128. methods: {
  129. play() {
  130. this.ctx.play();
  131. },
  132. pause() {
  133. this.ctx.pause();
  134. },
  135. stop() {
  136. this.ctx.stop();
  137. },
  138. onPlay(e) {
  139. this.$emit("play", e);
  140. },
  141. onPause(e) {
  142. this.$emit("pause", e);
  143. },
  144. onEnded(e) {
  145. this.$emit("ended", e);
  146. },
  147. onTimeUpdate(e) {
  148. this.$emit("timeupdate", e);
  149. },
  150. onWaiting(e) {
  151. this.$emit("waiting", e);
  152. },
  153. onError2(e) {
  154. this.$emit("error", e);
  155. },
  156. onProgress(e) {
  157. this.$emit("progress", e);
  158. },
  159. onLoadedMetaData(e) {
  160. this.$emit("loadedmetadata", e);
  161. },
  162. onFullScreenClick(e) {
  163. this.$emit("fullscreenclick", e);
  164. },
  165. onControlStoggle(e) {
  166. this.$emit("controlstoggle", e);
  167. }
  168. }
  169. };
  170. </script>