video.nvue 5.0 KB

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