vodShort.vue 6.1 KB

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