vodShort.vue 5.8 KB

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