video.nvue 6.2 KB

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