video.nvue 7.2 KB

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