video.nvue 7.3 KB

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