vodShort.vue 6.7 KB

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