|
@@ -59,7 +59,12 @@ export default defineComponent({
|
|
|
() => props.show,
|
|
|
val => {
|
|
|
if (val) {
|
|
|
+ data.vudio = null;
|
|
|
+ console.log(audioRef.value, 'audioRef.value');
|
|
|
// onToggleAudio();
|
|
|
+ audioRef.value?.addEventListener('loaded', () => {
|
|
|
+ console.log('111');
|
|
|
+ });
|
|
|
} else {
|
|
|
audioRef.value.pause();
|
|
|
data.playState = 'pause';
|
|
@@ -78,9 +83,12 @@ export default defineComponent({
|
|
|
|
|
|
// 切换音频播放
|
|
|
const onToggleAudio = () => {
|
|
|
+ console.log(audioRef.value.paused, 'audioRef.value.paused');
|
|
|
if (audioRef.value.paused) {
|
|
|
onInit(audioRef.value, canvasRef.value);
|
|
|
- audioRef.value.play();
|
|
|
+ audioRef.value.play().catch(e => {
|
|
|
+ console.log(e, '1111');
|
|
|
+ });
|
|
|
data.playState = 'play';
|
|
|
} else {
|
|
|
audioRef.value.pause();
|
|
@@ -89,33 +97,53 @@ export default defineComponent({
|
|
|
};
|
|
|
|
|
|
const onInit = (audio: undefined, canvas: undefined) => {
|
|
|
+ console.log(audio, canvas, data.vudio, 'Audio');
|
|
|
if (!data.vudio) {
|
|
|
- const rect = contetRef.value.getBoundingClientRect() || {
|
|
|
- width: 200,
|
|
|
- height: 200
|
|
|
- };
|
|
|
- data.vudio = new Vudio(audio, canvas, {
|
|
|
- effect: 'waveform',
|
|
|
- accuracy: 128,
|
|
|
- width: rect.width,
|
|
|
- height: rect.height,
|
|
|
- waveform: {
|
|
|
- maxHeight: 160,
|
|
|
- color: [
|
|
|
- [0, '#44D1FF'],
|
|
|
- [0.5, '#44D1FF'],
|
|
|
- [0.5, '#198CFE'],
|
|
|
- [1, '#198CFE']
|
|
|
- ],
|
|
|
- prettify: false
|
|
|
- }
|
|
|
- });
|
|
|
- data.vudio.dance();
|
|
|
+ try {
|
|
|
+ const rect = contetRef.value.getBoundingClientRect() || {
|
|
|
+ width: 200,
|
|
|
+ height: 200
|
|
|
+ };
|
|
|
+ data.vudio = new Vudio(audio, canvas, {
|
|
|
+ effect: 'waveform',
|
|
|
+ accuracy: 128,
|
|
|
+ width: rect.width,
|
|
|
+ height: rect.height,
|
|
|
+ waveform: {
|
|
|
+ maxHeight: 160,
|
|
|
+ color: [
|
|
|
+ [0, '#44D1FF'],
|
|
|
+ [0.5, '#44D1FF'],
|
|
|
+ [0.5, '#198CFE'],
|
|
|
+ [1, '#198CFE']
|
|
|
+ ],
|
|
|
+ prettify: false
|
|
|
+ }
|
|
|
+ });
|
|
|
+ data.vudio.dance();
|
|
|
+ } catch (e) {
|
|
|
+ console.log(e, 'e');
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
/** 加载成功 */
|
|
|
const onLoadedmetadata = () => {
|
|
|
- data.duration = audioRef.value.duration;
|
|
|
+ data.duration = audioRef.value?.duration;
|
|
|
+
|
|
|
+ // if (props.item.autoPlay && audioRef.value && props.show) {
|
|
|
+ // data.vudio = null;
|
|
|
+ // onToggleAudio();
|
|
|
+ // }
|
|
|
+
|
|
|
+ // if (audioRef.value) {
|
|
|
+ // audioRef.value.stop = () => {
|
|
|
+ // audioRef.value?.pause();
|
|
|
+ // };
|
|
|
+ // audioRef.value.onPlay = () => {
|
|
|
+ // audioRef.value?.play();
|
|
|
+ // onInit(audioRef.value, canvasRef.value);
|
|
|
+ // };
|
|
|
+ // }
|
|
|
};
|
|
|
|
|
|
/** 改变播放时间 */
|
|
@@ -175,7 +203,7 @@ export default defineComponent({
|
|
|
|
|
|
// 开始拖动时也不能更新
|
|
|
if (data.dragStatus) return;
|
|
|
- data.currentTime = audioRef.value.currentTime;
|
|
|
+ data.currentTime = audioRef.value?.currentTime;
|
|
|
}}
|
|
|
onError={() => {
|
|
|
console.log('error');
|