vodShort.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template name="vodShort">
  2. <view>
  3. <swiper class="swiper" autoplay="false" vertical="true" interval="990000" @change="changeVideo">
  4. <swiper-item v-for="(v, k) in item.text">
  5. <video
  6. :src="v.video"
  7. preload
  8. :muted="muted"
  9. show-play-btn="true"
  10. controls="false"
  11. v
  12. loop="true"
  13. :id="`video_${v.order}`"
  14. objectFit="fill"
  15. :enable-progress-gesture="false"
  16. @click="clickVideo"
  17. ref="video_url"
  18. play-btn-position="center"
  19. class="video"
  20. :poster="v.pic"
  21. @timeupdate="timeupdate">
  22. </video>
  23. <cover-image
  24. class="play" v-if="show_play"
  25. @tap="videoPlay"
  26. src="../../static/video/play.png"></cover-image>
  27. <cover-view class="cover-view-left">
  28. <text class="view-left-text">@{{ v.name }}</text>
  29. <view class="view-left-text-content">
  30. <text class="text-content-text">{{ v.name }}</text>
  31. </view>
  32. </cover-view>
  33. <cover-view class="cover-view-right">
  34. <cover-image :src="item.pic"
  35. class="avater img"
  36. @click.stop="tapAvater"></cover-image>
  37. <text class="right-follow">+</text>
  38. <cover-image
  39. style="position:relative;top:-20upx;"
  40. :src="up ? '../../static/video/axc.png' : '../../static/video/bed.png'"
  41. class="img-left" @click.stop="tapLove"></cover-image>
  42. <text class="right-text">1</text>
  43. <cover-image src="../../static/video/ay2.png"
  44. style="height: 80upx;" class="img-left" @click.stop="tapMsg"></cover-image>
  45. <text class="right-text">10</text>
  46. <cover-image src="../../static/video/b6p.png"
  47. style="height: 76upx;" class="img-left" @click.stop="tapShare"></cover-image>
  48. <text class="right-text">10</text>
  49. <cover-image src="../../static/video/changpian.png" class="musicIcon img">
  50. </cover-image>
  51. <cover-view class="progressBar" :animation="animationData" ></cover-view>
  52. </cover-view>
  53. </swiper-item>
  54. </swiper>
  55. </view>
  56. </template>
  57. <script>
  58. var play = false;
  59. export default {
  60. name: "vodShort",
  61. props: {
  62. item : {
  63. type : Object,
  64. value : null
  65. },
  66. },
  67. data() {
  68. return {
  69. up: false,
  70. time: 0,
  71. barWidth:0,
  72. animationData: {},
  73. times:null,
  74. play: false,
  75. show_play:false,
  76. muted: true,
  77. current_index: 0
  78. };
  79. },
  80. created() {
  81. setTimeout(()=>{
  82. play = true;
  83. this.videoPlay();
  84. },1000)
  85. },
  86. methods:{
  87. timeupdate(event) {
  88. let t_w = parseInt(this.width);
  89. this.duration = event.detail.duration;
  90. this.time = event.detail.currentTime;
  91. let width = (this.time / this.duration) * t_w;
  92. let w = 0;
  93. },
  94. clickVideo() {
  95. // console.log('单视频点击事件');
  96. this.videoPlay();
  97. },
  98. videoPlay() {
  99. console.info(this.item.text);
  100. let video_id = this.item.text[this.current_index].order;
  101. if (play) {
  102. console.log('播放视频',`video_${video_id}`);
  103. this.muted = false;
  104. this.videoCtx = uni.createVideoContext(`video_${video_id}`, this);
  105. this.videoCtx.play();
  106. this.show_play = false;
  107. play = false;
  108. } else {
  109. console.log('暂停视频',`video_${video_id}`);
  110. this.muted = true;
  111. this.videoCtx = uni.createVideoContext(`video_${video_id}`, this);
  112. this.videoCtx.pause();
  113. this.show_play = true;
  114. play = true;
  115. }
  116. },
  117. videoPause() {
  118. let video_id = this.item.text[this.current_index].order;
  119. this.videoCtx = uni.createVideoContext(`video_${video_id}`, this);
  120. this.videoCtx.pause();
  121. this.show_play = true;
  122. play = true;
  123. },
  124. changeVideo(e){
  125. // 暂停之前的视频
  126. this.videoPause();
  127. this.current_index = e.detail.current;
  128. console.log(e.detail.current);
  129. // 播放现在的视频
  130. this.videoPlay();
  131. // 判断是否第一条
  132. if( e.detail.current == 0 ){
  133. console.log('到顶了');
  134. return false;
  135. }
  136. // 判断是否最后一条
  137. if( e.detail.current == this.item.text.length-1 ){
  138. console.log('到底了');
  139. return false;
  140. }
  141. },
  142. tapMsg(e) {
  143. console.log(5, e);
  144. },
  145. tapShare(e) {
  146. console.log(6, e);
  147. },
  148. tapLove(e) {
  149. // item.is_dianzan
  150. this.item.text[this.current_index].is_dianzan = !this.item.text[this.current_index].is_dianzan;
  151. console.log(7, e);
  152. }
  153. },
  154. watch: {
  155. play(newVal, oldVal) {
  156. this.videoPlay();
  157. }
  158. }
  159. }
  160. </script>
  161. <style>
  162. .swiper{
  163. width: 100vw;
  164. height: 100vh;
  165. position: fixed;
  166. top: 0;
  167. left: 0;
  168. }
  169. .video {
  170. width: 100%;
  171. height: 100%;
  172. position: relative;
  173. }
  174. .play{
  175. position: absolute;
  176. width: 20vw;
  177. height: 20vw;
  178. left: 40vw;
  179. top: 40vh;
  180. opacity: 0.5;
  181. }
  182. .progressBar {
  183. border-radius: 2upx;
  184. height: 4upx;
  185. background-color: #FF4500;
  186. z-index: 999999;
  187. position: absolute;
  188. bottom: 68rpx;
  189. }
  190. .cover-view-left {
  191. position: absolute;
  192. margin-left: 20upx;
  193. width: 580upx;
  194. bottom: 110upx;
  195. z-index: 9999;
  196. font-size: 14px;
  197. color: #ffffff;
  198. }
  199. .left-text {
  200. font-size: 14px;
  201. color: #ffffff;
  202. }
  203. .cover-view-right {
  204. position: absolute;
  205. bottom: 40px;
  206. right: 30upx;
  207. z-index: 9999;
  208. text-align: center;
  209. }
  210. .avater {
  211. border-radius: 50%;
  212. border-width: 2px;
  213. border-style: solid;
  214. border-color: #ffffff;
  215. }
  216. .img {
  217. height: 90upx;
  218. width: 90upx;
  219. margin-bottom: 110upx;
  220. }
  221. .img-left {
  222. width: 80upx;
  223. height: 66upx;
  224. padding-left: 4px;
  225. }
  226. .right-follow {
  227. position: absolute;
  228. z-index: 100;
  229. top: 75upx;
  230. left: 28upx;
  231. color: #ffffff;
  232. font-size: 16px;
  233. width: 34upx;
  234. height: 34upx;
  235. background-color: #f12f5b;
  236. text-align: center;
  237. line-height: 34upx;
  238. border-radius: 17upx;
  239. }
  240. .right-text {
  241. color: #ffffff;
  242. font-size: 11px;
  243. text-align: center;
  244. margin-bottom: 40upx;
  245. }
  246. .musicIcon {
  247. margin-top: 40upx;
  248. }
  249. @keyframes rotating {
  250. from {
  251. transform: rotate(0);
  252. }
  253. to {
  254. transform: rotate(360deg);
  255. }
  256. }
  257. .view-left-text-content {
  258. flex: 1;
  259. }
  260. .view-left-text {
  261. color: #ffffff;
  262. font-size: 18px;
  263. margin-bottom: 10upx;
  264. font-weight: bold;
  265. }
  266. .text-content-text {
  267. color: #ffffff;
  268. font-size: 16px;
  269. line-height: 50upx;
  270. height: 100upx;
  271. overflow: hidden;
  272. }
  273. </style>