video.nvue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template name="dever-video">
  2. <view>
  3. <view class="player">
  4. <video
  5. :src="src"
  6. preload
  7. :autoplay="false"
  8. :show-mute-btn="true"
  9. :muted="muted"
  10. :show-play-btn="true"
  11. :show-center-play-btn="false"
  12. :controls="control"
  13. :loop="true"
  14. :id="id()"
  15. :objectFit="objectFit"
  16. :enable-progress-gesture="false"
  17. play-btn-position="center"
  18. class="video"
  19. :playsinline="true"
  20. :webkit-playsinline="true"
  21. x-webkit-airplay="allow"
  22. x5-video-player-type="h5-page"
  23. :page-gesture="false"
  24. @timeupdate="timeUpdate"
  25. @play="onPlay"
  26. @pause="onPause"
  27. @ended="onPause"
  28. >
  29. </video>
  30. </view>
  31. <view class="control" @click="open" :style="control_style">
  32. <cover-image v-if="poster && pic" class="poster" :src="pic">
  33. </cover-image>
  34. <cover-image
  35. class="ico-video-play" v-if="!playButton"></cover-image>
  36. <dever-position :item="position_item" :down="src" :button="position_save" v-if="position_item"></dever-position>
  37. <cover-view class="cover-view-right" v-if="showInfo">
  38. <cover-image :src="pic"
  39. class="avater img"
  40. @click.stop="tapAvater"></cover-image>
  41. <text class="right-follow">+</text>
  42. <cover-image
  43. style="position:relative;top:-20upx;"
  44. :src="up ? '../../static/video/axc.png' : '../../static/video/bed.png'"
  45. class="img-left" @click.stop="tapLove"></cover-image>
  46. <text class="right-text">1</text>
  47. <cover-image src="@/static/video/ay2.png"
  48. style="height: 80upx;" class="img-left" @click.stop="tapMsg"></cover-image>
  49. <text class="right-text">10</text>
  50. <cover-image src="@/static/video/b6p.png"
  51. style="height: 76upx;" class="img-left" @click.stop="tapShare"></cover-image>
  52. <text class="right-text">10</text>
  53. <cover-image src="@/static/video/changpian.png" class="musicIcon img">
  54. </cover-image>
  55. </cover-view>
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. import deverPosition from "@/lib/dever/components/position.vue";
  61. export default {
  62. props: {
  63. src : {
  64. type : String,
  65. value : null
  66. },
  67. index : {
  68. type : Number,
  69. value : null
  70. },
  71. vid : {
  72. type : String,
  73. value : null
  74. },
  75. pic : {
  76. type : String,
  77. value : null
  78. },
  79. auto : {
  80. type : Boolean,
  81. value : false
  82. },
  83. control : {
  84. type : Boolean,
  85. value : false
  86. },
  87. disabled : {
  88. type : Boolean,
  89. value : false
  90. },
  91. position_item : {
  92. type : Array,
  93. value : null
  94. },
  95. position_save : {
  96. type : String,
  97. value : null
  98. },
  99. type : {
  100. type : String,
  101. value : 1
  102. },
  103. },
  104. data() {
  105. return {
  106. objectFit : 'fill',
  107. play : false,
  108. playButton : false,
  109. muted : true,
  110. poster : true,
  111. video : false,
  112. showInfo : false,
  113. time : {},
  114. control_style : '',
  115. };
  116. },
  117. mounted() {
  118. if (this.type == 2) {
  119. this.objectFit = '';
  120. }
  121. this.video = uni.createVideoContext(this.id(), this);
  122. if (this.auto) {
  123. this.start();
  124. }
  125. },
  126. methods:{
  127. //获取video_id
  128. id : function() {
  129. return 'video_' + this.vid + '_' + this.index;
  130. },
  131. onPlay : function() {
  132. if (this.control) {
  133. this.control_style = 'height:0%;width:0%';
  134. this.setStart();
  135. }
  136. },
  137. onPause : function() {
  138. if (this.control) {
  139. this.control_style = 'height:100%;width:100%';
  140. this.stop(true);
  141. }
  142. },
  143. setStart : function() {
  144. this.$emit('update:load', true);
  145. this.$emit('play', 'start');
  146. this.poster = false;
  147. this.play = true;
  148. this.playButton = true;
  149. this.muted = false;
  150. },
  151. start : function() {
  152. if (this.disabled) {
  153. this.Dever.alert('无权限播放,请先购买座位');
  154. return;
  155. }
  156. this.setStart();
  157. this.video.play();
  158. },
  159. stop : function(state) {
  160. var self = this;
  161. //this.poster = true;
  162. if (state) {
  163. if (this.play) {
  164. self.video.pause();
  165. }
  166. this.playButton = false;
  167. } else {
  168. /*
  169. setTimeout(function() {
  170. self.video.pause();
  171. }, 1000);
  172. */
  173. }
  174. this.muted = true;
  175. this.play = false;
  176. this.$emit('play', 'stop');
  177. },
  178. open : function() {
  179. if (!this.play) {
  180. this.start();
  181. } else {
  182. this.stop(true);
  183. }
  184. },
  185. tapMsg : function(e) {
  186. console.log(5, e);
  187. },
  188. tapShare : function(e) {
  189. console.log(6, e);
  190. },
  191. tapLove : function(e) {
  192. // item.is_dianzan
  193. this.item[this.current_index].is_dianzan = !this.item[this.current_index].is_dianzan;
  194. console.log(7, e);
  195. },
  196. timeUpdate : function(e) {
  197. if (this.play == true) {
  198. var currentTime = e.detail.currentTime;
  199. currentTime = parseInt(currentTime);
  200. if (!this.time[currentTime]) {
  201. this.time[currentTime] = currentTime;
  202. this.$emit('play', 'time', currentTime);
  203. //记录播放进度
  204. //this.Dever.data('video_' + this.item.id, this.hall);
  205. }
  206. }
  207. }
  208. },
  209. components:{
  210. deverPosition
  211. }
  212. }
  213. </script>
  214. <style scoped>
  215. .control {
  216. width: 100%;
  217. height: 100%;
  218. z-index: 2;
  219. background: transparent;
  220. position: absolute;
  221. left: 0;
  222. top: 0;
  223. overflow: hidden;
  224. }
  225. .player {
  226. width: 100%;
  227. height: 100%;
  228. overflow: hidden;
  229. z-index: 1;
  230. background: transparent;
  231. position: absolute;
  232. left: 0;
  233. top: 0;
  234. overflow: hidden;
  235. }
  236. .video {
  237. /*
  238. width: 101%;
  239. height: 101%;
  240. margin-left: -5rpx;
  241. margin-top: -5rpx;
  242. */
  243. width:100%;
  244. height:100%;
  245. position: relative;
  246. background-color: transparent;
  247. z-index: 1;
  248. }
  249. .uni-video-bar {
  250. z-index:10;
  251. }
  252. .poster{
  253. background-size: cover;
  254. position: absolute;
  255. left: 0;
  256. top: 0;
  257. width: 100%;
  258. height: 100%;
  259. }
  260. .ico-video-play{
  261. background: url(@/static/icon/ico-video-play.png) no-repeat;
  262. background-size: cover;
  263. width: 100rpx;
  264. height: 100rpx;
  265. position: absolute;
  266. left: 50%;
  267. top: 50%;
  268. transform: translate3d(-50%,-50%,0);
  269. }
  270. .cover-view-left {
  271. position: absolute;
  272. margin-left: 20upx;
  273. width: 580upx;
  274. bottom: 110upx;
  275. z-index: 9999;
  276. font-size: 14px;
  277. color: #ffffff;
  278. }
  279. .left-text {
  280. font-size: 14px;
  281. color: #ffffff;
  282. }
  283. .cover-view-right {
  284. position: absolute;
  285. bottom: 40px;
  286. right: 30upx;
  287. z-index: 9999;
  288. text-align: center;
  289. }
  290. .avater {
  291. border-radius: 50%;
  292. border-width: 2px;
  293. border-style: solid;
  294. border-color: #ffffff;
  295. }
  296. .img {
  297. height: 90upx;
  298. width: 90upx;
  299. margin-bottom: 110upx;
  300. }
  301. .img-left {
  302. width: 80upx;
  303. height: 66upx;
  304. padding-left: 4px;
  305. }
  306. .right-follow {
  307. position: absolute;
  308. z-index: 100;
  309. top: 75upx;
  310. left: 28upx;
  311. color: #ffffff;
  312. font-size: 16px;
  313. width: 34upx;
  314. height: 34upx;
  315. background-color: #f12f5b;
  316. text-align: center;
  317. line-height: 34upx;
  318. border-radius: 17upx;
  319. }
  320. .right-text {
  321. color: #ffffff;
  322. font-size: 11px;
  323. text-align: center;
  324. margin-bottom: 40upx;
  325. }
  326. .musicIcon {
  327. margin-top: 40upx;
  328. }
  329. @keyframes rotating {
  330. from {
  331. transform: rotate(0);
  332. }
  333. to {
  334. transform: rotate(360deg);
  335. }
  336. }
  337. .view-left-text-content {
  338. flex: 1;
  339. }
  340. .view-left-text {
  341. color: #ffffff;
  342. font-size: 18px;
  343. margin-bottom: 10upx;
  344. font-weight: bold;
  345. }
  346. .text-content-text {
  347. color: #ffffff;
  348. font-size: 16px;
  349. line-height: 50upx;
  350. height: 100upx;
  351. overflow: hidden;
  352. }
  353. </style>