videoDetails.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <view class="container" v-loading="loading">
  3. <video
  4. v-if="videoInfo.url"
  5. class="container-video"
  6. id="myVideo"
  7. @timeupdate="timeUpdate"
  8. :src="videoInfo.url"
  9. controls
  10. :initial-time="videoInfo.initial_time"
  11. object-fit="fill"
  12. play-btn-position="center"
  13. @ended="videoEnded"
  14. @tap="videoClick"
  15. @loadedmetadata="loadedmetadata"
  16. >
  17. <cover-view class="video-control">
  18. <cover-view class="multi rate" @tap.stop="showSwitchRate">x {{ videoInfo.currentRate }}</cover-view>
  19. </cover-view>
  20. <cover-view class="multi-list rate" :class="{ active: rateShow }">
  21. <cover-view
  22. v-for="(item, index) in rateList"
  23. :key="index"
  24. class="multi-item rate"
  25. :data-rate="item"
  26. @tap="switchRate"
  27. :class="{ active: item == videoInfo.currentRate }"
  28. >
  29. {{ item }}
  30. </cover-view>
  31. </cover-view>
  32. </video>
  33. </view>
  34. </template>
  35. <script>
  36. export default {
  37. data() {
  38. return {
  39. loading: false,
  40. videoInfo: {
  41. url: '',
  42. initial_time: '',
  43. currentRate: 1.0
  44. },
  45. // 视频创建dom
  46. videoContext: uni.createVideoContext('myVideo', this),
  47. // 倍速
  48. rateList: [0.5, 1.0, 1.5, 2.0],
  49. rateShow: false
  50. };
  51. },
  52. onLoad(options) {
  53. const { chapterName, videoUrl } = options
  54. if (videoUrl) {
  55. this.videoInfo.url = videoUrl
  56. }
  57. this.loading = true;
  58. },
  59. methods: {
  60. videoClick() {},
  61. timeUpdate() {},
  62. videoEnded() {},
  63. loadedmetadata() {
  64. this.loading = false;
  65. },
  66. showSwitchRate() {
  67. this.rateShow = true;
  68. },
  69. switchRate(e) {
  70. let rate = Number(e.currentTarget.dataset.rate);
  71. this.videoInfo.currentRate = rate;
  72. this.rateShow = false;
  73. this.videoContext.playbackRate(rate);
  74. }
  75. }
  76. };
  77. </script>
  78. <style lang="scss" scoped>
  79. @import './videoDetails.scss';
  80. </style>