Browse Source

Merge branch 'new_dev' of github.com:deepcloud2048/deep_voice into new_dev

weicu
lxm 1 year ago
parent
commit
de7fc3938e
  1. 4
      local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt
  2. 4
      local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureSpeechPlugin.swift
  3. 112
      local_plugins/qq_music/android/src/main/kotlin/com/yunqiinnovation/qq_music/QQMusicSingleton.kt

4
local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt

@ -362,6 +362,7 @@ object AgentService : CoroutineScope {
setPackage(context.packageName)
}
context.sendBroadcast(intent)
Log.e(TAG, "QQ 音乐暂停播放")
QQMusicSingleton.getInstance().autopauseMusic { result ->
if (result.isSuccess) {
isplaymusic = true
@ -380,6 +381,7 @@ object AgentService : CoroutineScope {
context.sendBroadcast(intent)
if(isplaymusic){
isplaymusic = false
Log.e(TAG, "QQ 音乐恢复播放")
QQMusicSingleton.getInstance().resumeMusic { }
}
}
@ -2025,7 +2027,7 @@ object AgentService : CoroutineScope {
val songMids = songs.mapNotNull { song ->
song["mid"] as? String
}.filter { it.isNotEmpty() }
Log.w(TAG, "processQQMusicPlayList 开始播放音乐 $songMids")
if (songMids.isNotEmpty()) {
qqMusicSingleton.playSongs(songMids, 0) { result ->
result.onSuccess {

4
local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureSpeechPlugin.swift

@ -941,7 +941,7 @@ extension AzureSpeechPlugin: BleService.Callback {
os_log("音频流未初始化", type: .error)
return
}
print("liwei--------------接收到音频数据回调")
// print("liwei--------------接收到音频数据回调")
audioStream.saveAudioDataTo(data: data)
}
@ -953,7 +953,7 @@ extension AzureSpeechPlugin: BleService.Callback {
os_log("音频流未初始化", type: .error)
return
}
print("liwei--------------接收到音频数据回调1")
// print("liwei--------------接收到音频数据回调1")
audioStream.saveAudioDataTo(data: data)
}

112
local_plugins/qq_music/android/src/main/kotlin/com/yunqiinnovation/qq_music/QQMusicSingleton.kt

@ -321,98 +321,45 @@ class QQMusicSingleton private constructor() {
index: Int = 0,
callback: (Result<Unit>) -> Unit
) {
if (!isQQMusicInstalled()){
callback(Result.failure(Exception("未安装QQ音乐软件,请先安装QQ音乐软件")))
return
}
playWithRetry(songMids, index, callback)
Log.e(TAG, "播放音乐列表: $songMids")
executePlaybackAction("播放列表") { musicManager, playCallback ->
musicManager.playSongs(songMids, index,playCallback)
}(callback)
}
/**
* 带自动登录检查的播放实现
* 播放音乐
*/
private fun playWithRetry(
songMids: List<String>,
index: Int,
callback: (Result<Unit>) -> Unit
) {
val currentActivity = context
if (currentActivity == null) {
callback(Result.failure(Exception("Activity not available")))
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)
}
fun playMusic(callback: (Result<Unit>) -> Unit) {
executePlaybackAction("播放") { musicManager, playCallback ->
musicManager.playMusic(playCallback)
}(callback)
}
/**
* 执行播放歌曲列表操作
* 暂停音乐
*/
private fun performPlaySongs(
songMids: List<String>,
index: Int,
callback: (Result<Unit>) -> Unit
) {
val currentActivity = context ?: return
ensureMusicManager(currentActivity)
musicManager?.playSongs(songMids, index, object : QQMusicManager.PlayCallback {
fun pauseMusic(callback: (Result<Unit>) -> Unit) {
if (context == null || musicManager == null) {
callback(Result.failure(Exception("服务未初始化")))
return
}
musicManager?.pauseMusic(object : QQMusicManager.PlayCallback {
override fun onSuccess() {
handler.post {
Log.d(TAG, "播放歌曲列表成功")
Log.d(TAG, "暂停成功")
callback(Result.success(Unit))
}
}
override fun onError(errorCode: Int, errorMessage: String) {
handler.post {
Log.e(TAG, "播放失败: $errorCode $errorMessage")
if (errorCode == -1){
musicManager?.bindQQMusicApiService()
callback(Result.failure(Exception("播放失败: $errorMessage")))
} else if (errorCode == 1030) {
callback(Result.success(Unit))
}else{
callback(Result.failure(Exception("播放失败: $errorMessage")))
}
Log.e(TAG, "暂停失败: $errorMessage")
callback(Result.failure(Exception("暂停失败: $errorMessage")))
}
}
})
}
/**
* 播放音乐
*/
fun playMusic(callback: (Result<Unit>) -> Unit) {
executePlaybackAction("播放") { musicManager, playCallback ->
musicManager.playMusic(playCallback)
}(callback)
}
/**
* 暂停音乐
*/
fun pauseMusic(callback: (Result<Unit>) -> Unit) {
executePlaybackAction("暂停") { musicManager, playCallback ->
musicManager.pauseMusic(playCallback)
}(callback)
}
/**
@ -609,6 +556,12 @@ class QQMusicSingleton private constructor() {
action: (QQMusicManager, QQMusicManager.PlayCallback) -> Unit
): (callback: (Result<Unit>) -> Unit) -> Unit {
return lambda@{ callback ->
if (!isQQMusicInstalled()){
callback(Result.failure(Exception("未安装QQ音乐软件,请先安装QQ音乐软件")))
return@lambda
}
val currentActivity = context
if (currentActivity == null) {
callback(Result.failure(Exception("Activity not available")))
@ -626,8 +579,15 @@ class QQMusicSingleton private constructor() {
override fun onError(errorCode: Int, errorMessage: String) {
handler.post {
Log.e(TAG, "${actionName}失败: $errorMessage")
callback(Result.failure(Exception("${actionName}失败: $errorMessage")))
Log.e(TAG, "播放失败: $errorCode $errorMessage")
if (errorCode == -1){
musicManager?.bindQQMusicApiService()
callback(Result.failure(Exception("播放失败: $errorMessage")))
} else if (errorCode == 1030) {
callback(Result.success(Unit))
}else{
callback(Result.failure(Exception("播放失败: $errorMessage")))
}
}
}
})

Loading…
Cancel
Save