play.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <view class="play-container">
  3. <!--播放数据-->
  4. <view class="view-num main-left cross-center">
  5. <u-icon name="eye-fill" :color="$colors.primaryColor" size="26rpx" />
  6. <text>321</text>
  7. </view>
  8. <!--按钮-->
  9. <view class="status-bar dir-top-wrap main-center">
  10. <view class="item fav dir-top-wrap main-center cross-center">
  11. <u-icon name="heart-fill" size="58rpx" :color="$colors.primaryColor" />
  12. <text class="active">3.2k</text>
  13. </view>
  14. <view class="item collect dir-top-wrap main-center cross-center">
  15. <u-icon name="star-fill" size="58rpx" :color="$colors.defaultColor" />
  16. <text>3.2k</text>
  17. </view>
  18. <view class="item share dir-top-wrap main-center cross-center">
  19. <u-icon name="share-fill" size="58rpx" :color="$colors.defaultColor" />
  20. <text>3.2k</text>
  21. </view>
  22. </view>
  23. <!--底部-->
  24. <view class="footer main-between cross-center">
  25. <view class="icon" />
  26. <view class="name">
  27. <u-text text="jldjklsjgkldjglkdfhgklfdhgkldhgjklfhjkfhgjkfdhgjkdfhgk" :color="$colors.infoColor" :lines="1" />
  28. </view>
  29. <view class="arrow">
  30. <u-icon name="arrow-up" :color="$colors.infoColor" size="32rpx" />
  31. </view>
  32. </view>
  33. <!--视频播放-->
  34. <view class="video-box main-center cross-center">
  35. <!-- 控制按钮 - 播放 -->
  36. <view v-if="!isPlaying" class="play-btn main-center cross-center" @tap="handlePlay">
  37. <u-icon name="play-right-fill" size="100rpx" :color="$colors.defaultColor" />
  38. </view>
  39. <!-- 控制按钮 - 暂停 -->
  40. <view v-if="isPlaying" class="pause-layer" @tap="handlePause" />
  41. <!--进度条-->
  42. <view v-if="isPlaying" class="progress-container">
  43. <view class="progress" :style="{width: progress+'%'}" />
  44. </view>
  45. <video
  46. id="video"
  47. :show-play-btn="playBtn"
  48. :show-fullscreen-btn="fullscreenBtn"
  49. :controls="controls"
  50. object-fit="contain"
  51. style="width: 100%;height: 100%;"
  52. poster="http://zhengda.oss-cn-chengdu.aliyuncs.com/zhangsiye/images/17ec18c234d9f808da0a83cd46749b32.jpg"
  53. src="http://zhengda.oss-cn-chengdu.aliyuncs.com/zhangsiye/files/002fa937509b428ca12c826c28aba7c4.mp4"
  54. @timeupdate="timeupdate"
  55. />
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. export default {
  61. name: 'Play',
  62. data() {
  63. return {
  64. id: null,
  65. isPlaying: false,
  66. videoContext: null,
  67. controls: false,
  68. fullscreenBtn: false,
  69. playBtn: false,
  70. progress: 0
  71. }
  72. },
  73. computed: {},
  74. methods: {
  75. timeupdate({ detail }) {
  76. // currentTime, duration
  77. if (detail.duration) {
  78. this.progress = (detail.currentTime / detail.duration * 100).toFixed(2)
  79. }
  80. console.log('-->data', detail)
  81. // this.progress =
  82. },
  83. handlePlay() {
  84. this.isPlaying = true
  85. this.videoContext.play()
  86. },
  87. handlePause() {
  88. if (!this.isPlaying) return
  89. this.isPlaying = false
  90. this.videoContext.pause()
  91. }
  92. },
  93. onLoad(options) {
  94. this.videoContext = uni.createVideoContext('video', this)
  95. this.id = options.id
  96. }
  97. }
  98. </script>
  99. <style lang="scss" scoped>
  100. .play-container {
  101. font-size: 28rpx;
  102. .video-box{
  103. position: fixed;
  104. top: 0;
  105. left: 0;
  106. right: 0;
  107. bottom: 0;
  108. .play-btn{
  109. position: absolute;
  110. top: 0;
  111. left: 0;
  112. bottom: 0;
  113. right: 0;
  114. background: rgba(255,255,255,0);
  115. z-index: 99;
  116. }
  117. .pause-layer{
  118. position: absolute;
  119. top: 0;
  120. left: 0;
  121. bottom: 0;
  122. right: 0;
  123. background: transparent;
  124. z-index: 99;
  125. }
  126. video{
  127. position: absolute;
  128. z-index: 98;
  129. }
  130. .progress-container{
  131. width: 93vw;
  132. background: #fff;
  133. height: 10rpx;
  134. position: fixed;
  135. z-index: 100;
  136. bottom: 160rpx;
  137. .progress{
  138. height: 10rpx;
  139. background: linear-gradient(270deg, #6EEBE8 0%, #FF74B9 100%);
  140. }
  141. }
  142. }
  143. .view-num{
  144. position: fixed;
  145. right: 20rpx;
  146. top: 40rpx;
  147. color: #fff;
  148. font-size: 26rpx;
  149. z-index: 100;
  150. text{
  151. margin-left: 10rpx;
  152. }
  153. }
  154. .status-bar{
  155. position: fixed;
  156. bottom: 300rpx;
  157. right: 40rpx;
  158. color: $default-color;
  159. z-index: 100;
  160. .item{
  161. margin-bottom: 40rpx;
  162. text{
  163. margin-top: 10rpx;
  164. &.active{
  165. color: $primary-color;
  166. }
  167. }
  168. }
  169. }
  170. .footer{
  171. position: fixed;
  172. width: 95vw;
  173. height: 76rpx;
  174. background: rgba(24, 28, 47, 0.8);
  175. bottom: 50rpx;
  176. left: 50%;
  177. transform: translateX(-50%);
  178. font-size: 26rpx;
  179. color: $info-color;
  180. border-radius: 20rpx;
  181. padding: 0 20rpx;
  182. z-index: 100;
  183. .icon{
  184. background: url("/static/image/video.png") no-repeat center;
  185. background-size: 70%;
  186. width: 80rpx;
  187. height: 80rpx;
  188. }
  189. .name{
  190. text-align: left;
  191. flex: 1;
  192. padding: 0 30rpx;
  193. }
  194. }
  195. }
  196. </style>