fix bugs.3

This commit is contained in:
2025-12-05 21:05:01 +08:00
parent b4ffa086fb
commit 60b910c38f
6 changed files with 61 additions and 234 deletions

View File

@@ -184,7 +184,7 @@ public class AgoraManager {
rtcEngine = (RtcEngineEx) RtcEngine.create(config);
} catch (Exception e) {
Log.e("AgoraManager", "Failed to create RtcEngine", e);
LogUtils.e("AgoraManager", "Failed to create RtcEngine", e);
return;
}
@@ -213,13 +213,13 @@ public class AgoraManager {
"}");
rtcEngine.setParameters("{\"che.video.mobile_1080p\":true}");
} catch (Exception e) {
Log.w("AgoraManager", "Failed to set parameters", e);
LogUtils.w("AgoraManager", "Failed to set parameters", e);
}
rtcEngine.enableVideo();
rtcEngine.setDefaultAudioRoutetoSpeakerphone(true);
} catch (Exception e) {
Log.e("AgoraManager", "Failed to configure RtcEngine", e);
LogUtils.e("AgoraManager", "Failed to configure RtcEngine", e);
}
}
}
@@ -240,7 +240,7 @@ public class AgoraManager {
*/
public void joinRoom(String token, String roomId, int uid, boolean isMicrophoneEnabled, boolean isCamerJs) {
if (rtcEngine == null) {
Log.e("AgoraManager", "RtcEngine not initialized");
LogUtils.e("AgoraManager", "RtcEngine not initialized");
init(CommonAppContext.getInstance().getCurrentEnvironment().getSwSdkAppId());
}
if (!mRoomId.isEmpty()) {
@@ -294,7 +294,7 @@ public class AgoraManager {
rtcEngine.leaveChannel();
}
} catch (Exception e) {
Log.e("AgoraManager", "Error during cleanup", e);
LogUtils.e("AgoraManager", "Error during cleanup", e);
} finally {
// 注意不要在这里将rtcEngine设置为null
// 应该在destroy方法中处理
@@ -563,7 +563,7 @@ public class AgoraManager {
@Override
public void onFirstRemoteAudioFrame(int uid, int elapsed) {
super.onFirstRemoteAudioFrame(uid, elapsed);
Log.i("RoomCabinFragment", "onFirstRemoteAudioFrame: uid->" + uid);
LogUtils.i("RoomCabinFragment", "onFirstRemoteAudioFrame: uid->" + uid);
}
@@ -584,7 +584,7 @@ public class AgoraManager {
@Override
public void onRemoteVideoStateChanged(int uid, int state, int reason, int elapsed) {
super.onRemoteVideoStateChanged(uid, state, reason, elapsed);
Log.i("RoomCabinFragment", "onRemoteVideoStateChanged:uid->" + uid + ", state->" + state);
LogUtils.i("RoomCabinFragment", "onRemoteVideoStateChanged:uid->" + uid + ", state->" + state);
if (state == Constants.REMOTE_AUDIO_STATE_STOPPED) {
ColoseCardEvent renderView = new ColoseCardEvent();
EventBus.getDefault().post(renderView);
@@ -1002,7 +1002,7 @@ public class AgoraManager {
LogUtils.e("AgoraManager", "isPreload: " + songCode);
// 确保 rtcEngine 已初始化
if (rtcEngine == null) {
Log.e("AgoraManager", "RtcEngine not initialized, cannot preload music");
LogUtils.e("AgoraManager", "RtcEngine not initialized, cannot preload music");
init(CommonAppContext.getInstance().getCurrentEnvironment().getSwSdkAppId());
return;
}
@@ -1012,11 +1012,11 @@ public class AgoraManager {
try {
musicContentCenter = IAgoraMusicContentCenter.create(rtcEngine);
if (musicContentCenter == null) {
Log.e("AgoraManager", "Failed to create musicContentCenter");
LogUtils.e("AgoraManager", "Failed to create musicContentCenter");
return;
}
} catch (Exception e) {
Log.e("AgoraManager", "Exception creating musicContentCenter", e);
LogUtils.e("AgoraManager", "Exception creating musicContentCenter", e);
return;
}
}
@@ -1026,11 +1026,11 @@ public class AgoraManager {
try {
musicPlayer = musicContentCenter.createMusicPlayer();
if (musicPlayer == null) {
Log.e("AgoraManager", "Failed to create musicPlayer");
LogUtils.e("AgoraManager", "Failed to create musicPlayer");
return;
}
} catch (Exception e) {
Log.e("AgoraManager", "Exception creating musicPlayer", e);
LogUtils.e("AgoraManager", "Exception creating musicPlayer", e);
return;
}
}
@@ -1039,7 +1039,7 @@ public class AgoraManager {
try {
code = musicContentCenter.isPreloaded(mSongCode);
} catch (Exception e) {
Log.e("AgoraManager", "Exception checking if song is preloaded", e);
LogUtils.e("AgoraManager", "Exception checking if song is preloaded", e);
return;
}
@@ -1050,13 +1050,13 @@ public class AgoraManager {
executeInBackground(() -> {
try {
Thread.sleep(3000); // 3秒延迟
Log.d("AgoraManager", "Preload result: " + result);
LogUtils.d("AgoraManager", "Preload result: " + result);
// 切换回主线程执行后续操作
createTrackedHandler(Looper.getMainLooper()).post(() -> {
isPreload(mSongCode, type);
});
} catch (Exception e) {
Log.e("AgoraManager", "Preload song failed: songCode=" + mSongCode, e);
LogUtils.e("AgoraManager", "Preload song failed: songCode=" + mSongCode, e);
}
});
} else {
@@ -1069,20 +1069,20 @@ public class AgoraManager {
executeInBackground(() -> {
try {
Thread.sleep(3000); // 3秒延迟
Log.d("AgoraManager", "Preload result: " + result);
LogUtils.d("AgoraManager", "Preload result: " + result);
// 切换回主线程执行后续操作
createTrackedHandler(Looper.getMainLooper()).post(() -> {
isPreload(mSongCode, type);
});
} catch (Exception e) {
Log.e("AgoraManager", "Preload song failed: songCode=" + mSongCode, e);
LogUtils.e("AgoraManager", "Preload song failed: songCode=" + mSongCode, e);
}
});
} else {
try {
musicPlayer.open(mSongCode, 0);
} catch (Exception e) {
Log.e("AgoraManager", "Open music failed: songCode=" + mSongCode, e);
LogUtils.e("AgoraManager", "Open music failed: songCode=" + mSongCode, e);
}
}
}
@@ -1091,7 +1091,7 @@ public class AgoraManager {
// 提取音乐播放器状态处理逻辑到单独的方法
private void handleMusicPlayerState(long songCode) {
if (musicPlayer == null) {
Log.e("AgoraManager", "Music player is null, cannot handle state");
LogUtils.e("AgoraManager", "Music player is null, cannot handle state");
return;
}
@@ -1114,7 +1114,7 @@ public class AgoraManager {
isPreload(songCode, 1);
});
} catch (Exception e) {
Log.e("AgoraManager", "Error in idle state handling", e);
LogUtils.e("AgoraManager", "Error in idle state handling", e);
}
});
break;
@@ -1150,7 +1150,7 @@ public class AgoraManager {
break;
}
} catch (Exception e) {
Log.e("AgoraManager", "Exception handling music player state", e);
LogUtils.e("AgoraManager", "Exception handling music player state", e);
}
}
@@ -1305,7 +1305,7 @@ public class AgoraManager {
musicList.remove(musicList.get(0));
});
} catch (Exception e) {
Log.e("AgoraManager", "Error in nextSong", e);
LogUtils.e("AgoraManager", "Error in nextSong", e);
}
});
@@ -1393,7 +1393,7 @@ public class AgoraManager {
public static byte[] convertFileToByteArray(File file) {
if (file == null || !file.exists()) {
Log.e("AgoraManager", "File is null or does not exist");
LogUtils.e("AgoraManager", "File is null or does not exist");
return null;
}
@@ -1404,16 +1404,16 @@ public class AgoraManager {
byteArray = new byte[(int) file.length()];
int bytesRead = fis.read(byteArray);
if (bytesRead != byteArray.length) {
Log.w("AgoraManager", "Could not read entire file: " + file.getPath());
LogUtils.w("AgoraManager", "Could not read entire file: " + file.getPath());
}
} catch (Exception e) {
Log.e("AgoraManager", "Error converting file to byte array", e);
LogUtils.e("AgoraManager", "Error converting file to byte array", e);
} finally {
if (fis != null) {
try {
fis.close();
} catch (Exception e) {
Log.e("AgoraManager", "Error closing file input stream", e);
LogUtils.e("AgoraManager", "Error closing file input stream", e);
}
}
}