Kaynağa Gözat

fix: 修复播放器自动播放问题

- setPlaylist 添加 autoPlay 参数控制是否自动播放
- 播放器页面不再自动播放第一首
- 移除音频结束后的自动连播功能
MyFramework User 5 ay önce
ebeveyn
işleme
4465e6f465

+ 2 - 2
client/src/pages/player/index.vue

@@ -159,10 +159,10 @@ async function fetchPlaylist() {
       pageSize: 100,
     });
     
-    // 设置播放列表
+    // 设置播放列表(不自动播放,因为已经在 fetchAudio 中播放了当前音频)
     const index = result.list.findIndex(item => item._id === audioId.value);
     if (index >= 0) {
-      audioStore.setPlaylist(result.list, index);
+      audioStore.setPlaylist(result.list, index, false);
     }
   } catch (error) {
     console.error('获取播放列表失败:', error);

+ 3 - 6
client/src/store/audio.ts

@@ -38,10 +38,7 @@ export const useAudioStore = defineStore('audio', () => {
 
     audioContext.onEnded(() => {
       isPlaying.value = false;
-      // 自动播放下一首
-      if (hasNext.value) {
-        playNext();
-      }
+      // 不自动播放下一首,让用户手动选择
     });
 
     audioContext.onTimeUpdate(() => {
@@ -156,10 +153,10 @@ export const useAudioStore = defineStore('audio', () => {
   }
 
   // 设置播放列表
-  function setPlaylist(list: AudioItem[], index: number = 0) {
+  function setPlaylist(list: AudioItem[], index: number = 0, autoPlay: boolean = true) {
     playlist.value = list;
     currentIndex.value = index;
-    if (list.length > 0) {
+    if (list.length > 0 && autoPlay) {
       play(list[index]);
     }
   }