@@ -588,6 +588,12 @@ class Player {
588
588
*/
589
589
async pause ( changeStatus : boolean = true ) {
590
590
const statusStore = useStatusStore ( ) ;
591
+
592
+ // 播放器未加载完成
593
+ if ( this . player . state ( ) !== "loaded" ) {
594
+ return
595
+ }
596
+
591
597
// 淡出
592
598
await new Promise < void > ( ( resolve ) => {
593
599
this . player . fade ( statusStore . playVolume , 0 , this . getFadeTime ( ) ) ;
@@ -873,23 +879,24 @@ class Player {
873
879
// 尝试添加
874
880
const songIndex = await dataStore . setNextPlaySong ( song , statusStore . playIndex ) ;
875
881
// 播放歌曲
876
- if ( ! songIndex ) return ;
877
- if ( play ) this . togglePlayIndex ( songIndex ) ;
882
+ if ( songIndex < 0 ) return ;
883
+ if ( play ) this . togglePlayIndex ( songIndex , true ) ;
878
884
else window . $message . success ( "已添加至下一首播放" ) ;
879
885
}
880
886
/**
881
887
* 切换播放索引
882
888
* @param index 播放索引
889
+ * @param play 是否立即播放
883
890
*/
884
- async togglePlayIndex ( index : number ) {
891
+ async togglePlayIndex ( index : number , play : boolean = false ) {
885
892
const dataStore = useDataStore ( ) ;
886
893
const statusStore = useStatusStore ( ) ;
887
894
// 获取数据
888
895
const { playList } = dataStore ;
889
896
// 若超出播放列表
890
897
if ( index >= playList . length ) return ;
891
898
// 相同
892
- if ( statusStore . playIndex === index ) {
899
+ if ( ! play && statusStore . playIndex === index ) {
893
900
this . play ( ) ;
894
901
return ;
895
902
}
@@ -915,6 +922,8 @@ class Player {
915
922
this . cleanPlayList ( ) ;
916
923
return ;
917
924
}
925
+ // 是否为当前播放歌曲
926
+ const isCurrentPlay = statusStore . playIndex === index ;
918
927
// 深拷贝,防止影响原数据
919
928
const newPlaylist = cloneDeep ( playList ) ;
920
929
// 若将移除最后一首
@@ -929,7 +938,7 @@ class Player {
929
938
newPlaylist . splice ( index , 1 ) ;
930
939
dataStore . setPlayList ( newPlaylist ) ;
931
940
// 若为当前播放
932
- if ( statusStore . playIndex === index ) {
941
+ if ( isCurrentPlay ) {
933
942
this . initPlayer ( statusStore . playStatus ) ;
934
943
}
935
944
}
@@ -949,6 +958,7 @@ class Player {
949
958
showFullPlayer : false ,
950
959
playHeartbeatMode : false ,
951
960
personalFmMode : false ,
961
+ playIndex : - 1 ,
952
962
} ) ;
953
963
musicStore . resetMusicData ( ) ;
954
964
dataStore . setPlayList ( [ ] ) ;
0 commit comments