audio-pay.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { defineComponent, onMounted, toRefs } from 'vue';
  2. import styles from './audio.module.less';
  3. import WaveSurfer from 'wavesurfer.js';
  4. import iconplay from '../image/icon-pause.svg';
  5. import iconpause from '../image/icon-play.svg';
  6. export default defineComponent({
  7. name: 'audio-play',
  8. props: {
  9. item: {
  10. type: Object,
  11. default: () => {
  12. return {};
  13. }
  14. },
  15. isEmtry: {
  16. type: Boolean,
  17. default: false
  18. }
  19. },
  20. setup(props) {
  21. const { item, isEmtry } = toRefs(props);
  22. const audioId = 'a' + +Date.now() + Math.floor(Math.random() * 100);
  23. onMounted(() => {
  24. const audio = new Audio();
  25. audio.controls = true;
  26. audio.style.width = '100%';
  27. audio.className = styles.audio;
  28. document.querySelector(`#${audioId}`)?.appendChild(audio);
  29. const wavesurfer = WaveSurfer.create({
  30. container: document.querySelector(`#${audioId}`) as HTMLElement,
  31. waveColor: '#C5C5C5',
  32. progressColor: '#02baff',
  33. url: item.value.content + '?t=' + +new Date(),
  34. cursorWidth: 0,
  35. height: 160,
  36. normalize: true,
  37. // Set a bar width
  38. barWidth: 6,
  39. // Optionally, specify the spacing between bars
  40. barGap: 12,
  41. // And the bar radius
  42. barRadius: 12,
  43. autoScroll: true,
  44. /** If autoScroll is enabled, keep the cursor in the center of the waveform during playback */
  45. autoCenter: true,
  46. hideScrollbar: false,
  47. media: audio
  48. });
  49. wavesurfer.once('interaction', () => {
  50. // wavesurfer.play();
  51. });
  52. });
  53. return () => (
  54. <div class={styles.audioWrap}>
  55. <div class={styles.audioContainer}>
  56. <div id={audioId}></div>
  57. </div>
  58. <div class={styles.controls}></div>
  59. {/* <div
  60. class="plyr__controls bottomFixed ${styles.controls}">
  61. <div class="${styles.actions}">
  62. <div class="${styles.actionWrap}">
  63. <button id="${playBtnId}" class="${styles.actionBtn}">
  64. <div
  65. class="van-loading van-loading--circular"
  66. aria-live="polite"
  67. aria-busy="true">
  68. <span
  69. class="van-loading__spinner van-loading__spinner--circular"
  70. style="color: rgb(255, 255, 255);">
  71. <svg class="van-loading__circular" viewBox="25 25 50 50">
  72. <circle cx="50" cy="50" r="20" fill="none"></circle>
  73. </svg>
  74. </span>
  75. </div>
  76. <img class="${styles.playIcon}" src="${iconplay}" />
  77. <img class="${styles.playIcon}" src="${iconpause}" />
  78. </button>
  79. </div>
  80. <div class="${styles.time}">
  81. <div
  82. class="plyr__time plyr__time--current"
  83. aria-label="Current time">
  84. 00:00
  85. </div>
  86. <span class="${styles.line}">/</span>
  87. <div
  88. class="plyr__time plyr__time--duration"
  89. aria-label="Duration">
  90. 00:00
  91. </div>
  92. </div>
  93. </div>
  94. <div class="${styles.slider}">
  95. <div class="plyr__progress">
  96. <input data-plyr="seek" type="range" min="0" max="100" step="0.01" value="0" aria-label="Seek">
  97. <progress class="plyr__progress__buffer" min="0" max="100" value="0">% buffered</progress>
  98. <span role="tooltip" class="plyr__tooltip">
  99. 00:00
  100. </span>
  101. </div>
  102. </div>
  103. </div> */}
  104. </div>
  105. );
  106. }
  107. });