import { defineComponent, onMounted, toRefs } from 'vue'; import styles from './audio.module.less'; import WaveSurfer from 'wavesurfer.js'; import iconplay from '../image/icon-pause.svg'; import iconpause from '../image/icon-play.svg'; export default defineComponent({ name: 'audio-play', props: { item: { type: Object, default: () => { return {}; } }, isEmtry: { type: Boolean, default: false } }, setup(props) { const { item, isEmtry } = toRefs(props); const audioId = 'a' + +Date.now() + Math.floor(Math.random() * 100); onMounted(() => { const audio = new Audio(); audio.controls = true; audio.style.width = '100%'; audio.className = styles.audio; document.querySelector(`#${audioId}`)?.appendChild(audio); const wavesurfer = WaveSurfer.create({ container: document.querySelector(`#${audioId}`) as HTMLElement, waveColor: '#C5C5C5', progressColor: '#02baff', url: item.value.content + '?t=' + +new Date(), cursorWidth: 0, height: 160, normalize: true, // Set a bar width barWidth: 6, // Optionally, specify the spacing between bars barGap: 12, // And the bar radius barRadius: 12, autoScroll: true, /** If autoScroll is enabled, keep the cursor in the center of the waveform during playback */ autoCenter: true, hideScrollbar: false, media: audio }); wavesurfer.once('interaction', () => { // wavesurfer.play(); }); }); return () => (