video.nvue 6.4 KB

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