video.vue 7.3 KB

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