video.nvue 6.2 KB

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