video.nvue 5.8 KB

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