Jelajahi Sumber

简化代码逻辑

黄琪勇 11 bulan lalu
induk
melakukan
42900426f9
1 mengubah file dengan 3 tambahan dan 13 penghapusan
  1. 3 13
      src/view/audio-list/index.tsx

+ 3 - 13
src/view/audio-list/index.tsx

@@ -146,14 +146,8 @@ export const toggleMutePlayAudio = (source: IPlayState, muted: boolean) => {
 
 
 /** 切换节拍器音源 */
 /** 切换节拍器音源 */
 export const changeSongSourceByBate = (isDisBate:boolean) => {
 export const changeSongSourceByBate = (isDisBate:boolean) => {
+	const currentTime = getAudioCurrentTime()
 	// isDisBate 为true 切换到不带节拍的,为false 切换到带节拍的
 	// isDisBate 为true 切换到不带节拍的,为false 切换到带节拍的
-	let currentTime
-	if(state.playSource === "mingSong"){
-		currentTime = audioData.mingSongEle?.currentTime
-	}else{
-		currentTime = audioData.songEle?.currentTime || audioData.backgroundEle?.currentTime
-	}
-	currentTime || (currentTime = audioData.progress || 0)
 	if (isDisBate) {
 	if (isDisBate) {
 		if(state.playType === "play"){
 		if(state.playType === "play"){
 			audioData.songEle = audioData.songCollection.songEle
 			audioData.songEle = audioData.songCollection.songEle
@@ -174,12 +168,8 @@ export const changeSongSourceByBate = (isDisBate:boolean) => {
 			audioData.mingSongEle = audioData.songCollection.betaMingSongEle || audioData.songCollection.mingSongEle
 			audioData.mingSongEle = audioData.songCollection.betaMingSongEle || audioData.songCollection.mingSongEle
 		}
 		}
 	}
 	}
-	audioData.songEle && (audioData.songEle.currentTime = currentTime)
-	audioData.backgroundEle && (audioData.backgroundEle.currentTime = currentTime)
-	// 当前是唱名才设置时间
-	if(state.playSource === "mingSong") {
-		audioData.mingSongEle && (audioData.mingSongEle.currentTime = currentTime)
-	}
+	// 设置进度
+	setAudioCurrentTime(currentTime)
 	// 设置静音与取消静音
 	// 设置静音与取消静音
 	if (state.playSource === "music") {
 	if (state.playSource === "music") {
 		audioData.songEle && (audioData.songEle.muted = false);
 		audioData.songEle && (audioData.songEle.muted = false);