vodShort.vue 6.0 KB

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