Browse Source

上传修复代码

newdev_shunjiawei
liwei1dao 1 year ago
parent
commit
1e8c0278f5
  1. 9
      lib/data/services/qq_musoc.dart
  2. 2
      local_plugins/qq_music/android/src/main/kotlin/com/yunqiinnovation/qq_music/QQMusicManager.kt
  3. 57
      local_plugins/qq_music/android/src/main/kotlin/com/yunqiinnovation/qq_music/QQMusicSingleton.kt

9
lib/data/services/qq_musoc.dart

@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:ffi';
import 'package:get/get.dart';
import 'package:qq_music/qq_music.dart';
import '../models/song_model.dart';
@ -36,7 +37,7 @@ class QqMusocService extends GetxService {
if (result['success'] == true) {
print('QQ音乐自动登录成功: ${result['openId']}');
Future.delayed(Duration(milliseconds: 1000), () {
syncCurrentPlayInfo();
syncCurrentPlayInfo(isFrest: true);
});
} else {
print('QQ音乐自动登录失败: ${result['error']}');
@ -420,7 +421,8 @@ class QqMusocService extends GetxService {
}
/// 同步当前播放信息 - 统一接口
Future<Map<String, dynamic>> syncCurrentPlayInfo() async {
Future<Map<String, dynamic>> syncCurrentPlayInfo(
{bool isFrest = false}) async {
try {
_stateMonitorTimer?.cancel(); //先关闭计时器
final result = await _qqMusic.syncCurrentPlayInfo();
@ -468,6 +470,9 @@ class QqMusocService extends GetxService {
if (newIsPlaying) {
//正在播放
startPlaybackStateMonitor();
} else {
stopPlaybackStateMonitor();
currentSong.value = null;
}
// 通知所有监听器
_notifyListeners();

2
local_plugins/qq_music/android/src/main/kotlin/com/yunqiinnovation/qq_music/QQMusicManager.kt

@ -95,7 +95,7 @@ class QQMusicManager(private val activity: Activity) {
}
}
private fun bindQQMusicApiService() {
fun bindQQMusicApiService() {
Log.d(TAG, "开始绑定QQ音乐服务,平台类型: ${Config.BIND_PLATFORM}")
val intent = when (Config.BIND_PLATFORM) {

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

@ -311,23 +311,63 @@ class QQMusicSingleton private constructor() {
}
/**
* 播放歌曲列表
* 播放歌曲列表(带自动登录检查)
*/
fun playSongs(
songMids: List<String>,
index: Int = 0,
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
if (currentActivity == null) {
callback(Result.failure(Exception("Activity not available")))
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)
musicManager?.playSongs(songMids, index, object : QQMusicManager.PlayCallback {
override fun onSuccess() {
@ -340,10 +380,13 @@ class QQMusicSingleton private constructor() {
override fun onError(errorCode: Int, errorMessage: String) {
handler.post {
Log.e(TAG, "播放失败: $errorCode $errorMessage")
if (errorCode != 1030) {
if (errorCode == -1){
musicManager?.bindQQMusicApiService()
callback(Result.failure(Exception("播放失败: $errorMessage")))
}else{
} else if (errorCode == 1030) {
callback(Result.success(Unit))
}else{
callback(Result.failure(Exception("播放失败: $errorMessage")))
}
}
}

Loading…
Cancel
Save