video.nvue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <template name="dever-video">
  2. <view>
  3. <view class="player">
  4. <video
  5. :src="src"
  6. preload
  7. autoplay
  8. :muted="!play"
  9. :show-play-btn="true"
  10. :show-center-play-btn="false"
  11. :controls="false"
  12. :loop="true"
  13. :id="id()"
  14. objectFit="fill"
  15. :enable-progress-gesture="false"
  16. play-btn-position="center"
  17. class="video"
  18. :playsinline="true"
  19. :webkit-playsinline="true"
  20. x-webkit-airplay="allow"
  21. x5-video-player-type="h5-page"
  22. :initial-time="startTime"
  23. >
  24. </video>
  25. </view>
  26. <view class="control" @click="open">
  27. <cover-image v-if="poster" class="poster" :src="pic">
  28. </cover-image>
  29. <cover-image
  30. class="ico-video-play" v-if="!play"></cover-image>
  31. <pos :item="item" :down="src" v-if="item"></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>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. import pos from "@/pages/dream/view/pos.vue";
  56. export default {
  57. name: "dever-video",
  58. props: {
  59. item : {
  60. type : Object,
  61. value : null
  62. },
  63. src : {
  64. type : String,
  65. value : null
  66. },
  67. index : {
  68. type : Number,
  69. value : null
  70. },
  71. vid : {
  72. type : String,
  73. value : null
  74. },
  75. pic : {
  76. type : String,
  77. value : null
  78. },
  79. },
  80. data() {
  81. return {
  82. startTime : 0,
  83. play : false,
  84. poster : true,
  85. video : false,
  86. showInfo : false,
  87. };
  88. },
  89. mounted() {
  90. this.video = uni.createVideoContext(this.id(), this);
  91. },
  92. methods:{
  93. //获取video_id
  94. id : function() {
  95. return 'video_' + this.vid + '_' + this.index;
  96. },
  97. start : function() {
  98. this.poster = false;
  99. this.video.play();
  100. this.play = true;
  101. },
  102. stop : function() {
  103. var self = this;
  104. //this.poster = true;
  105. this.startTime = 0;
  106. setTimeout(function() {
  107. self.video.pause();
  108. }, 500);
  109. this.play = false;
  110. },
  111. open : function() {
  112. if (!this.play) {
  113. this.start();
  114. } else {
  115. this.stop();
  116. }
  117. },
  118. },
  119. components:{
  120. pos
  121. }
  122. }
  123. </script>
  124. <style scoped>
  125. .control {
  126. width: 100%;
  127. height: 100%;
  128. z-index: 2;
  129. background: transparent;
  130. position: absolute;
  131. left: 0;
  132. top: 0;
  133. overflow: hidden;
  134. }
  135. .player {
  136. width: 100%;
  137. height: 100%;
  138. overflow: hidden;
  139. z-index: 1;
  140. background: transparent;
  141. position: absolute;
  142. left: 0;
  143. top: 0;
  144. overflow: hidden;
  145. }
  146. .video {
  147. width: 101%;
  148. height: 101%;
  149. margin-left: -5rpx;
  150. margin-top: -5rpx;
  151. position: relative;
  152. background-color: transparent;
  153. z-index: 1;
  154. }
  155. .poster{
  156. background-size: cover;
  157. position: absolute;
  158. left: 0;
  159. top: 0;
  160. width: 100%;
  161. height: 100%;
  162. }
  163. .ico-video-play{
  164. background: url(@/static/icon/ico-video-play.png) no-repeat;
  165. background-size: cover;
  166. width: 100rpx;
  167. height: 100rpx;
  168. position: absolute;
  169. left: 50%;
  170. top: 50%;
  171. transform: translate3d(-50%,-50%,0);
  172. }
  173. .cover-view-left {
  174. position: absolute;
  175. margin-left: 20upx;
  176. width: 580upx;
  177. bottom: 110upx;
  178. z-index: 9999;
  179. font-size: 14px;
  180. color: #ffffff;
  181. }
  182. .left-text {
  183. font-size: 14px;
  184. color: #ffffff;
  185. }
  186. .cover-view-right {
  187. position: absolute;
  188. bottom: 40px;
  189. right: 30upx;
  190. z-index: 9999;
  191. text-align: center;
  192. }
  193. .avater {
  194. border-radius: 50%;
  195. border-width: 2px;
  196. border-style: solid;
  197. border-color: #ffffff;
  198. }
  199. .img {
  200. height: 90upx;
  201. width: 90upx;
  202. margin-bottom: 110upx;
  203. }
  204. .img-left {
  205. width: 80upx;
  206. height: 66upx;
  207. padding-left: 4px;
  208. }
  209. .right-follow {
  210. position: absolute;
  211. z-index: 100;
  212. top: 75upx;
  213. left: 28upx;
  214. color: #ffffff;
  215. font-size: 16px;
  216. width: 34upx;
  217. height: 34upx;
  218. background-color: #f12f5b;
  219. text-align: center;
  220. line-height: 34upx;
  221. border-radius: 17upx;
  222. }
  223. .right-text {
  224. color: #ffffff;
  225. font-size: 11px;
  226. text-align: center;
  227. margin-bottom: 40upx;
  228. }
  229. .musicIcon {
  230. margin-top: 40upx;
  231. }
  232. @keyframes rotating {
  233. from {
  234. transform: rotate(0);
  235. }
  236. to {
  237. transform: rotate(360deg);
  238. }
  239. }
  240. .view-left-text-content {
  241. flex: 1;
  242. }
  243. .view-left-text {
  244. color: #ffffff;
  245. font-size: 18px;
  246. margin-bottom: 10upx;
  247. font-weight: bold;
  248. }
  249. .text-content-text {
  250. color: #ffffff;
  251. font-size: 16px;
  252. line-height: 50upx;
  253. height: 100upx;
  254. overflow: hidden;
  255. }
  256. </style>