Skip to content

Commit 1c784d8

Browse files
HugoChaanCYG
andauthored
hotfix for 4.1.1.17 (#9)
Co-authored-by: CYG <[email protected]>
1 parent 3869cfc commit 1c784d8

File tree

1 file changed

+43
-38
lines changed
  • KTVAPI/Android/lib_ktvapi/src/main/java/io/agora/ktvapi

1 file changed

+43
-38
lines changed

KTVAPI/Android/lib_ktvapi/src/main/java/io/agora/ktvapi/KTVApiImpl.kt

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,7 @@ class KTVApiImpl : KTVApi, IMusicContentCenterEventHandler, IMediaPlayerObserver
817817
}
818818

819819
// 合唱
820+
private var handlerEx :IRtcEngineEventHandler? = null
820821
private fun joinChorus2ndChannel(
821822
newRole: KTVSingRole,
822823
token: String,
@@ -856,52 +857,55 @@ class KTVApiImpl : KTVApi, IMusicContentCenterEventHandler, IMediaPlayerObserver
856857
token,
857858
rtcConnection,
858859
channelMediaOption,
859-
object : IRtcEngineEventHandler() {
860-
override fun onJoinChannelSuccess(channel: String?, uid: Int, elapsed: Int) {
861-
Log.d(TAG, "onJoinChannel2Success: channel:$channel, uid:$uid")
862-
if (isRelease) return
863-
super.onJoinChannelSuccess(channel, uid, elapsed)
864-
if (newRole == KTVSingRole.LeadSinger) {
865-
mainSingerHasJoinChannelEx = true
866-
}
867-
onJoinChorus2ndChannelCallback(0)
868-
mRtcEngine.enableAudioVolumeIndicationEx(50, 10, true, rtcConnection)
860+
null)
861+
862+
val handler = object : IRtcEngineEventHandler() {
863+
override fun onJoinChannelSuccess(channel: String?, uid: Int, elapsed: Int) {
864+
Log.d(TAG, "onJoinChannel2Success: channel:$channel, uid:$uid")
865+
if (isRelease) return
866+
super.onJoinChannelSuccess(channel, uid, elapsed)
867+
if (newRole == KTVSingRole.LeadSinger) {
868+
mainSingerHasJoinChannelEx = true
869869
}
870+
onJoinChorus2ndChannelCallback(0)
871+
mRtcEngine.enableAudioVolumeIndicationEx(50, 10, true, rtcConnection)
872+
}
870873

871-
override fun onLeaveChannel(stats: RtcStats?) {
872-
Log.d(TAG, "onLeaveChannel2")
873-
if (isRelease) return
874-
super.onLeaveChannel(stats)
875-
if (newRole == KTVSingRole.LeadSinger) {
876-
mainSingerHasJoinChannelEx = false
877-
}
874+
override fun onLeaveChannel(stats: RtcStats?) {
875+
Log.d(TAG, "onLeaveChannel2")
876+
if (isRelease) return
877+
super.onLeaveChannel(stats)
878+
if (newRole == KTVSingRole.LeadSinger) {
879+
mainSingerHasJoinChannelEx = false
878880
}
881+
}
879882

880-
override fun onError(err: Int) {
881-
super.onError(err)
882-
if (isRelease) return
883-
if (err == ERR_JOIN_CHANNEL_REJECTED) {
884-
Log.e(TAG, "joinChorus2ndChannel failed: ERR_JOIN_CHANNEL_REJECTED")
885-
onJoinChorus2ndChannelCallback(ERR_JOIN_CHANNEL_REJECTED)
886-
} else if (err == ERR_LEAVE_CHANNEL_REJECTED) {
887-
Log.e(TAG, "leaveChorus2ndChannel failed: ERR_LEAVE_CHANNEL_REJECTED")
888-
}
883+
override fun onError(err: Int) {
884+
super.onError(err)
885+
if (isRelease) return
886+
if (err == ERR_JOIN_CHANNEL_REJECTED) {
887+
Log.e(TAG, "joinChorus2ndChannel failed: ERR_JOIN_CHANNEL_REJECTED")
888+
onJoinChorus2ndChannelCallback(ERR_JOIN_CHANNEL_REJECTED)
889+
} else if (err == ERR_LEAVE_CHANNEL_REJECTED) {
890+
Log.e(TAG, "leaveChorus2ndChannel failed: ERR_LEAVE_CHANNEL_REJECTED")
889891
}
892+
}
890893

891-
override fun onTokenPrivilegeWillExpire(token: String?) {
892-
super.onTokenPrivilegeWillExpire(token)
893-
ktvApiEventHandlerList.forEach { it.onTokenPrivilegeWillExpire() }
894-
}
894+
override fun onTokenPrivilegeWillExpire(token: String?) {
895+
super.onTokenPrivilegeWillExpire(token)
896+
ktvApiEventHandlerList.forEach { it.onTokenPrivilegeWillExpire() }
897+
}
895898

896-
override fun onAudioVolumeIndication(
897-
speakers: Array<out AudioVolumeInfo>?,
898-
totalVolume: Int
899-
) {
900-
super.onAudioVolumeIndication(speakers, totalVolume)
901-
ktvApiEventHandlerList.forEach { it.onChorusChannelAudioVolumeIndication(speakers, totalVolume) }
902-
}
899+
override fun onAudioVolumeIndication(
900+
speakers: Array<out AudioVolumeInfo>?,
901+
totalVolume: Int
902+
) {
903+
super.onAudioVolumeIndication(speakers, totalVolume)
904+
ktvApiEventHandlerList.forEach { it.onChorusChannelAudioVolumeIndication(speakers, totalVolume) }
903905
}
904-
)
906+
}
907+
handlerEx = handler
908+
mRtcEngine.addHandlerEx(handler, rtcConnection)
905909

906910
if (ret != 0) {
907911
Log.e(TAG, "joinChorus2ndChannel failed: $ret")
@@ -914,6 +918,7 @@ class KTVApiImpl : KTVApi, IMusicContentCenterEventHandler, IMediaPlayerObserver
914918
}
915919

916920
private fun leaveChorus2ndChannel(role: KTVSingRole) {
921+
mRtcEngine.removeHandlerEx(handlerEx, subChorusConnection)
917922
if (role == KTVSingRole.LeadSinger) {
918923
mRtcEngine.leaveChannelEx(subChorusConnection)
919924
} else if (role == KTVSingRole.CoSinger) {

0 commit comments

Comments
 (0)