video.nvue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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.video.play();
  165. },
  166. stop : function(state) {
  167. var self = this;
  168. //this.poster = true;
  169. if (state) {
  170. if (this.play) {
  171. self.video.pause();
  172. }
  173. this.playButton = false;
  174. } else {
  175. /*
  176. setTimeout(function() {
  177. self.video.pause();
  178. }, 1000);
  179. */
  180. }
  181. this.muted = true;
  182. this.play = false;
  183. this.$emit('play', 'stop');
  184. },
  185. open : function() {
  186. if (!this.play) {
  187. this.start();
  188. } else {
  189. this.stop(true);
  190. }
  191. },
  192. tapMsg : function(e) {
  193. console.log(5, e);
  194. },
  195. tapShare : function(e) {
  196. console.log(6, e);
  197. },
  198. tapLove : function(e) {
  199. // item.is_dianzan
  200. this.item[this.current_index].is_dianzan = !this.item[this.current_index].is_dianzan;
  201. console.log(7, e);
  202. },
  203. timeUpdate : function(e) {
  204. if (this.play == true) {
  205. var currentTime = e.detail.currentTime;
  206. currentTime = parseInt(currentTime);
  207. if (!this.time[currentTime]) {
  208. this.time[currentTime] = currentTime;
  209. this.$emit('play', 'time', currentTime);
  210. //记录播放进度
  211. this.Dever.data('video_' + this.vid, this.currentTime);
  212. }
  213. }
  214. }
  215. },
  216. components:{
  217. deverPosition
  218. }
  219. }
  220. </script>
  221. <style scoped>
  222. .control {
  223. width: 100%;
  224. height: 100%;
  225. z-index: 2;
  226. background: transparent;
  227. position: absolute;
  228. left: 0;
  229. top: 0;
  230. overflow: hidden;
  231. }
  232. .player {
  233. width: 100%;
  234. height: 100%;
  235. overflow: hidden;
  236. z-index: 1;
  237. background: transparent;
  238. position: absolute;
  239. left: 0;
  240. top: 0;
  241. overflow: hidden;
  242. }
  243. .video {
  244. /*
  245. width: 101%;
  246. height: 101%;
  247. margin-left: -5rpx;
  248. margin-top: -5rpx;
  249. */
  250. width:100%;
  251. height:100%;
  252. position: relative;
  253. background-color: transparent;
  254. z-index: 1;
  255. }
  256. .uni-video-bar {
  257. z-index:10;
  258. }
  259. .poster{
  260. background-size: cover;
  261. position: absolute;
  262. left: 0;
  263. top: 0;
  264. width: 100%;
  265. height: 100%;
  266. }
  267. .ico-video-play{
  268. background: url(@/static/icon/ico-video-play.png) no-repeat;
  269. background-size: cover;
  270. width: 100rpx;
  271. height: 100rpx;
  272. position: absolute;
  273. left: 50%;
  274. top: 50%;
  275. transform: translate3d(-50%,-50%,0);
  276. }
  277. .cover-view-left {
  278. position: absolute;
  279. margin-left: 20upx;
  280. width: 580upx;
  281. bottom: 110upx;
  282. z-index: 9999;
  283. font-size: 14px;
  284. color: #ffffff;
  285. }
  286. .left-text {
  287. font-size: 14px;
  288. color: #ffffff;
  289. }
  290. .cover-view-right {
  291. position: absolute;
  292. bottom: 40px;
  293. right: 30upx;
  294. z-index: 9999;
  295. text-align: center;
  296. }
  297. .avater {
  298. border-radius: 50%;
  299. border-width: 2px;
  300. border-style: solid;
  301. border-color: #ffffff;
  302. }
  303. .img {
  304. height: 90upx;
  305. width: 90upx;
  306. margin-bottom: 110upx;
  307. }
  308. .img-left {
  309. width: 80upx;
  310. height: 66upx;
  311. padding-left: 4px;
  312. }
  313. .right-follow {
  314. position: absolute;
  315. z-index: 100;
  316. top: 75upx;
  317. left: 28upx;
  318. color: #ffffff;
  319. font-size: 16px;
  320. width: 34upx;
  321. height: 34upx;
  322. background-color: #f12f5b;
  323. text-align: center;
  324. line-height: 34upx;
  325. border-radius: 17upx;
  326. }
  327. .right-text {
  328. color: #ffffff;
  329. font-size: 11px;
  330. text-align: center;
  331. margin-bottom: 40upx;
  332. }
  333. .musicIcon {
  334. margin-top: 40upx;
  335. }
  336. @keyframes rotating {
  337. from {
  338. transform: rotate(0);
  339. }
  340. to {
  341. transform: rotate(360deg);
  342. }
  343. }
  344. .view-left-text-content {
  345. flex: 1;
  346. }
  347. .view-left-text {
  348. color: #ffffff;
  349. font-size: 18px;
  350. margin-bottom: 10upx;
  351. font-weight: bold;
  352. }
  353. .text-content-text {
  354. color: #ffffff;
  355. font-size: 16px;
  356. line-height: 50upx;
  357. height: 100upx;
  358. overflow: hidden;
  359. }
  360. </style>