vodShort.vue 6.6 KB

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