video.nvue 5.7 KB

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