Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 新增加载音乐失败的处理方法 #211

Merged
merged 2 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/Hitokoto.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ const getHitokotoData = () => {
fill: "#efefef",
}),
});
hitokotoData.text = "这里应该显示一句话";
hitokotoData.from = "無名";
});
};

// 更新一言数据
const updateHitokoto = () => {
hitokotoData.text = "新的一言正在赶来的路上";
hitokotoData.from = "来源加载中";
// 防抖
debounce(() => {
getHitokotoData();
Expand Down
34 changes: 34 additions & 0 deletions src/components/Player.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
@pause="onPause"
@timeupdate="onTimeUp"
@onSelectSong="onSelectSong"
@error="loadMusicError"
/>
</template>

Expand All @@ -37,6 +38,8 @@ const playList = ref([]);
const playIndex = ref(0);
const playListCount = ref(0);

const skipTimeout = ref(null);

// 配置项
const props = defineProps({
// 音频自动播放
Expand Down Expand Up @@ -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>
Expand Down