|
|
@ -311,23 +311,63 @@ class QQMusicSingleton private constructor() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 播放歌曲列表 |
|
|
* 播放歌曲列表(带自动登录检查) |
|
|
*/ |
|
|
*/ |
|
|
fun playSongs( |
|
|
fun playSongs( |
|
|
songMids: List<String>, |
|
|
songMids: List<String>, |
|
|
index: Int = 0, |
|
|
index: Int = 0, |
|
|
callback: (Result<Unit>) -> Unit |
|
|
callback: (Result<Unit>) -> Unit |
|
|
) { |
|
|
) { |
|
|
|
|
|
if (!isQQMusicInstalled()){ |
|
|
|
|
|
callback(Result.failure(Exception("未安装QQ音乐软件,请先安装QQ音乐软件"))) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
playWithRetry(songMids, index, callback) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 带自动登录检查的播放实现 |
|
|
|
|
|
*/ |
|
|
|
|
|
private fun playWithRetry( |
|
|
|
|
|
songMids: List<String>, |
|
|
|
|
|
index: Int, |
|
|
|
|
|
callback: (Result<Unit>) -> Unit |
|
|
|
|
|
) { |
|
|
val currentActivity = activity |
|
|
val currentActivity = activity |
|
|
if (currentActivity == null) { |
|
|
if (currentActivity == null) { |
|
|
callback(Result.failure(Exception("Activity not available"))) |
|
|
callback(Result.failure(Exception("Activity not available"))) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
if (!isQQMusicInstalled()){ |
|
|
|
|
|
callback(Result.failure(Exception("未安装QQ音乐软件,请先安装QQ音乐软件"))) |
|
|
// 检查登录状态 |
|
|
return |
|
|
if (!isLoggedIn()) { |
|
|
|
|
|
Log.d(TAG, "播放前检测到未登录,开始自动登录") |
|
|
|
|
|
login { loginResult -> |
|
|
|
|
|
if (loginResult.isSuccess) { |
|
|
|
|
|
Log.d(TAG, "自动登录成功,等待QQ音乐服务连接...") |
|
|
|
|
|
handler.postDelayed({ |
|
|
|
|
|
Log.d(TAG, "等待完成,开始播放") |
|
|
|
|
|
performPlaySongs(songMids, index, callback) |
|
|
|
|
|
}, LOGIN_WAIT_DELAY_MS) |
|
|
|
|
|
} else { |
|
|
|
|
|
callback(Result.failure(Exception("自动登录失败: ${loginResult.exceptionOrNull()?.message}"))) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
performPlaySongs(songMids, index, callback) |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 执行播放歌曲列表操作 |
|
|
|
|
|
*/ |
|
|
|
|
|
private fun performPlaySongs( |
|
|
|
|
|
songMids: List<String>, |
|
|
|
|
|
index: Int, |
|
|
|
|
|
callback: (Result<Unit>) -> Unit |
|
|
|
|
|
) { |
|
|
|
|
|
val currentActivity = activity ?: return |
|
|
|
|
|
|
|
|
ensureMusicManager(currentActivity) |
|
|
ensureMusicManager(currentActivity) |
|
|
musicManager?.playSongs(songMids, index, object : QQMusicManager.PlayCallback { |
|
|
musicManager?.playSongs(songMids, index, object : QQMusicManager.PlayCallback { |
|
|
override fun onSuccess() { |
|
|
override fun onSuccess() { |
|
|
@ -340,10 +380,13 @@ class QQMusicSingleton private constructor() { |
|
|
override fun onError(errorCode: Int, errorMessage: String) { |
|
|
override fun onError(errorCode: Int, errorMessage: String) { |
|
|
handler.post { |
|
|
handler.post { |
|
|
Log.e(TAG, "播放失败: $errorCode $errorMessage") |
|
|
Log.e(TAG, "播放失败: $errorCode $errorMessage") |
|
|
if (errorCode != 1030) { |
|
|
if (errorCode == -1){ |
|
|
|
|
|
musicManager?.bindQQMusicApiService() |
|
|
callback(Result.failure(Exception("播放失败: $errorMessage"))) |
|
|
callback(Result.failure(Exception("播放失败: $errorMessage"))) |
|
|
}else{ |
|
|
} else if (errorCode == 1030) { |
|
|
callback(Result.success(Unit)) |
|
|
callback(Result.success(Unit)) |
|
|
|
|
|
}else{ |
|
|
|
|
|
callback(Result.failure(Exception("播放失败: $errorMessage"))) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|