fix: 修复播放异常问题(可能)

This commit is contained in:
imsyy
2023-05-09 16:52:30 +08:00
parent aace9e97b0
commit f4d2c5f337
3 changed files with 15 additions and 8 deletions

View File

@@ -82,6 +82,7 @@
<script setup>
import { musicStore } from "@/store";
import { DeleteFour } from "@icon-park/vue-next";
import { setSeek } from "@/utils/Player";
import AllArtists from "@/components/DataList/AllArtists.vue";
const music = musicStore();
@@ -91,8 +92,14 @@ const playListShow = ref(false);
// 改变播放索引
const changeIndex = (index) => {
music.persistData.playSongIndex = index;
music.setPlayState(true);
try {
music.persistData.playSongIndex = index;
setSeek($player, 0);
music.setPlayState(true);
} catch (err) {
console.error("切换失败:" + err);
$message.error("切换失败,请刷新后重试");
}
};
// 监听播放列表显隐

View File

@@ -426,7 +426,7 @@ watch(
() => music.getPlaySongData,
(val) => {
// 清除播放地址
soundUnload();
// soundUnload();
music.setPlaySongTime({ currentTime: 0, duration: 0 });
songChange(val);
}
@@ -451,8 +451,6 @@ watch(
val ? "play" : "pause",
persistData.value.playVolume
);
} else {
$message.error("播放器初始化失败,请重试");
}
});
}

View File

@@ -151,7 +151,7 @@ const useMusicDataStore = defineStore("musicData", {
this.persistData.personalFmMode = value;
if (value) {
soundUnload();
if (this.persistData.personalFmData.id) {
if (this.persistData.personalFmData?.id) {
this.persistData.playlists = [];
this.persistData.playlists.push(this.persistData.personalFmData);
this.persistData.playSongIndex = 0;
@@ -403,7 +403,8 @@ const useMusicDataStore = defineStore("musicData", {
fadePlayOrPause($player, "play", this.persistData.playVolume);
}
if (listMode !== "single" && listLength > 1) {
soundUnload();
// soundUnload();
setSeek($player, 0);
}
this.playState = true;
}
@@ -420,7 +421,8 @@ const useMusicDataStore = defineStore("musicData", {
this.persistData.playlists[this.persistData.playSongIndex]?.id
) {
console.log("播放歌曲与上一次不一致");
soundUnload();
// soundUnload();
setSeek($player, 0);
}
} catch (error) {
console.error("出现错误:" + error);