Merge pull request #211 from first19326/dev

feat: 新增加载音乐失败的处理方法
This commit is contained in:
底层用户 2023-11-08 15:50:46 +08:00 committed by GitHub
commit df854f3f19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 2 deletions

View File

@ -59,13 +59,13 @@ const getHitokotoData = () => {
fill: "#efefef",
}),
});
hitokotoData.text = "这里应该显示一句话";
hitokotoData.from = "無名";
});
};
//
const updateHitokoto = () => {
hitokotoData.text = "新的一言正在赶来的路上";
hitokotoData.from = "来源加载中";
//
debounce(() => {
getHitokotoData();

View File

@ -16,6 +16,7 @@
@pause="onPause"
@timeupdate="onTimeUp"
@onSelectSong="onSelectSong"
@error="loadMusicError"
/>
</template>
@ -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);
});
</script>
<style lang="scss" scoped>