From 46b187d01f40ef586e1542933e7bfff27da7fa4f Mon Sep 17 00:00:00 2001 From: first19326 <870390039@qq.com> Date: Sat, 4 Nov 2023 20:21:50 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E9=9F=B3=E4=B9=90=E5=A4=B1=E8=B4=A5=E7=9A=84=E5=A4=84?= =?UTF-8?q?=E7=90=86=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Player.vue | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/components/Player.vue b/src/components/Player.vue index 05870cacd9..626602c335 100644 --- a/src/components/Player.vue +++ b/src/components/Player.vue @@ -16,6 +16,7 @@ @pause="onPause" @timeupdate="onTimeUp" @onSelectSong="onSelectSong" + @error="loadMusicError" /> @@ -37,6 +38,8 @@ const playList = ref([]); const playIndex = ref(0); const playListCount = ref(0); +const skipTimeout = ref(null); + // 配置项 const props = defineProps({ // 音频自动播放 @@ -202,8 +205,39 @@ const changeSong = (type) => { }); }; +// 加载音频错误 +const loadMusicError = () => { + let notice = ""; + if (playList.value.length > 1) { + notice = "播放音频出现错误,播放器将在 2s 后进行跳转"; + // 播放下一首 + skipTimeout.value = setTimeout(() => { + changeSong(1); + if (!player.value.audio.paused) { + onPlay(); + } + }, 2000); + } else { + notice = "播放音频出现错误"; + } + ElMessage({ + message: notice, + grouping: true, + icon: h(PlayWrong, { + theme: "filled", + fill: "#EFEFEF", + duration: 2000, + }), + }); + console.error("播放音乐: " + player.value.currentMusic.title + " 出现错误"); +}; + // 暴露子组件方法 defineExpose({ playToggle, changeVolume, changeSong }); + +onBeforeUnmount(() => { + clearTimeout(skipTimeout.value); +});