|
@@ -3,6 +3,7 @@ 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';
|
|
|
+import { NSlider } from 'naive-ui';
|
|
|
|
|
|
export default defineComponent({
|
|
|
name: 'audio-play',
|
|
@@ -23,6 +24,7 @@ export default defineComponent({
|
|
|
const audioId = 'a' + +Date.now() + Math.floor(Math.random() * 100);
|
|
|
const audioForms = reactive({
|
|
|
paused: true,
|
|
|
+ currentTimeNum: 0,
|
|
|
currentTime: '00:00',
|
|
|
duration: '00:00'
|
|
|
});
|
|
@@ -59,8 +61,11 @@ export default defineComponent({
|
|
|
});
|
|
|
wavesurfer.once('ready', () => {
|
|
|
audioForms.paused = audioDom.paused;
|
|
|
- // console.log(audioDom.duration, wavesurfer.getDuration());
|
|
|
- audioForms.duration = timeFormat(audioDom.duration);
|
|
|
+ audioForms.duration = timeFormat(Math.round(audioDom.duration));
|
|
|
+ });
|
|
|
+
|
|
|
+ wavesurfer.on('finish', () => {
|
|
|
+ audioForms.paused = true;
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -76,11 +81,14 @@ export default defineComponent({
|
|
|
audioForms.paused = audioDom.paused;
|
|
|
};
|
|
|
|
|
|
+ // 播放时监听
|
|
|
audioDom.addEventListener('timeupdate', () => {
|
|
|
- console.log(audioDom.currentTime);
|
|
|
- audioForms.currentTime = timeFormat(Math.floor(audioDom.currentTime));
|
|
|
+ audioForms.currentTime = timeFormat(Math.round(audioDom.currentTime));
|
|
|
+ audioForms.currentTimeNum = audioDom.currentTime;
|
|
|
});
|
|
|
|
|
|
+ // 播放结束时
|
|
|
+
|
|
|
// 对时间进行格式化
|
|
|
const timeFormat = (num: number) => {
|
|
|
if (num > 0) {
|
|
@@ -95,10 +103,18 @@ export default defineComponent({
|
|
|
return () => (
|
|
|
<div class={styles.audioWrap}>
|
|
|
<div class={styles.audioContainer}>
|
|
|
- <div id={audioId}></div>
|
|
|
+ <div
|
|
|
+ id={audioId}
|
|
|
+ onClick={(e: MouseEvent) => {
|
|
|
+ e.stopPropagation();
|
|
|
+ }}></div>
|
|
|
</div>
|
|
|
|
|
|
- <div class={styles.controls}>
|
|
|
+ <div
|
|
|
+ class={styles.controls}
|
|
|
+ onClick={(e: MouseEvent) => {
|
|
|
+ e.stopPropagation();
|
|
|
+ }}>
|
|
|
<div class={styles.actions}>
|
|
|
<div class={styles.actionWrap}>
|
|
|
<button class={styles.actionBtn} onClick={onToggleAudio}>
|
|
@@ -124,28 +140,13 @@ export default defineComponent({
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
- <div class="${styles.slider}">
|
|
|
- <div class="plyr__progress">
|
|
|
- <input
|
|
|
- data-plyr="seek"
|
|
|
- type="range"
|
|
|
- min="0"
|
|
|
- max="100"
|
|
|
- step="0.01"
|
|
|
- value="0"
|
|
|
- aria-label="Seek"
|
|
|
- />
|
|
|
- <progress
|
|
|
- class="plyr__progress__buffer"
|
|
|
- // min="0"
|
|
|
- max="100"
|
|
|
- value="0">
|
|
|
- % buffered
|
|
|
- </progress>
|
|
|
- <span role="tooltip" class="plyr__tooltip">
|
|
|
- 00:00
|
|
|
- </span>
|
|
|
- </div>
|
|
|
+ <div class={styles.slider}>
|
|
|
+ <NSlider
|
|
|
+ v-model:value={audioForms.currentTimeNum}
|
|
|
+ step={0.01}
|
|
|
+ max={audioDom.duration}
|
|
|
+ tooltip={false}
|
|
|
+ />
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|