video.nvue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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.play = true;
  119. this.playButton = true;
  120. this.muted = false;
  121. },
  122. stop : function(state) {
  123. var self = this;
  124. //this.poster = true;
  125. if (state) {
  126. if (this.play) {
  127. self.video.pause();
  128. }
  129. this.playButton = false;
  130. } else {
  131. /*
  132. setTimeout(function() {
  133. self.video.pause();
  134. }, 1000);
  135. */
  136. }
  137. this.muted = true;
  138. this.play = false;
  139. },
  140. open : function() {
  141. if (!this.play) {
  142. this.start();
  143. } else {
  144. this.stop(true);
  145. }
  146. },
  147. tapMsg : function(e) {
  148. console.log(5, e);
  149. },
  150. tapShare : function(e) {
  151. console.log(6, e);
  152. },
  153. tapLove : function(e) {
  154. // item.is_dianzan
  155. this.item[this.current_index].is_dianzan = !this.item[this.current_index].is_dianzan;
  156. console.log(7, e);
  157. }
  158. },
  159. components:{
  160. position
  161. }
  162. }
  163. </script>
  164. <style scoped>
  165. .control {
  166. width: 100%;
  167. height: 100%;
  168. z-index: 2;
  169. background: transparent;
  170. position: absolute;
  171. left: 0;
  172. top: 0;
  173. overflow: hidden;
  174. }
  175. .player {
  176. width: 100%;
  177. height: 100%;
  178. overflow: hidden;
  179. z-index: 1;
  180. background: transparent;
  181. position: absolute;
  182. left: 0;
  183. top: 0;
  184. overflow: hidden;
  185. }
  186. .video {
  187. /*
  188. width: 101%;
  189. height: 101%;
  190. margin-left: -5rpx;
  191. margin-top: -5rpx;
  192. */
  193. width:100%;
  194. height:100%;
  195. position: relative;
  196. background-color: transparent;
  197. z-index: 1;
  198. }
  199. .poster{
  200. background-size: cover;
  201. position: absolute;
  202. left: 0;
  203. top: 0;
  204. width: 100%;
  205. height: 100%;
  206. }
  207. .ico-video-play{
  208. background: url(@/static/icon/ico-video-play.png) no-repeat;
  209. background-size: cover;
  210. width: 100rpx;
  211. height: 100rpx;
  212. position: absolute;
  213. left: 50%;
  214. top: 50%;
  215. transform: translate3d(-50%,-50%,0);
  216. }
  217. .cover-view-left {
  218. position: absolute;
  219. margin-left: 20upx;
  220. width: 580upx;
  221. bottom: 110upx;
  222. z-index: 9999;
  223. font-size: 14px;
  224. color: #ffffff;
  225. }
  226. .left-text {
  227. font-size: 14px;
  228. color: #ffffff;
  229. }
  230. .cover-view-right {
  231. position: absolute;
  232. bottom: 40px;
  233. right: 30upx;
  234. z-index: 9999;
  235. text-align: center;
  236. }
  237. .avater {
  238. border-radius: 50%;
  239. border-width: 2px;
  240. border-style: solid;
  241. border-color: #ffffff;
  242. }
  243. .img {
  244. height: 90upx;
  245. width: 90upx;
  246. margin-bottom: 110upx;
  247. }
  248. .img-left {
  249. width: 80upx;
  250. height: 66upx;
  251. padding-left: 4px;
  252. }
  253. .right-follow {
  254. position: absolute;
  255. z-index: 100;
  256. top: 75upx;
  257. left: 28upx;
  258. color: #ffffff;
  259. font-size: 16px;
  260. width: 34upx;
  261. height: 34upx;
  262. background-color: #f12f5b;
  263. text-align: center;
  264. line-height: 34upx;
  265. border-radius: 17upx;
  266. }
  267. .right-text {
  268. color: #ffffff;
  269. font-size: 11px;
  270. text-align: center;
  271. margin-bottom: 40upx;
  272. }
  273. .musicIcon {
  274. margin-top: 40upx;
  275. }
  276. @keyframes rotating {
  277. from {
  278. transform: rotate(0);
  279. }
  280. to {
  281. transform: rotate(360deg);
  282. }
  283. }
  284. .view-left-text-content {
  285. flex: 1;
  286. }
  287. .view-left-text {
  288. color: #ffffff;
  289. font-size: 18px;
  290. margin-bottom: 10upx;
  291. font-weight: bold;
  292. }
  293. .text-content-text {
  294. color: #ffffff;
  295. font-size: 16px;
  296. line-height: 50upx;
  297. height: 100upx;
  298. overflow: hidden;
  299. }
  300. </style>