@@ -817,6 +817,7 @@ class KTVApiImpl : KTVApi, IMusicContentCenterEventHandler, IMediaPlayerObserver
817
817
}
818
818
819
819
// 合唱
820
+ private var handlerEx : IRtcEngineEventHandler ? = null
820
821
private fun joinChorus2ndChannel (
821
822
newRole : KTVSingRole ,
822
823
token : String ,
@@ -856,52 +857,55 @@ class KTVApiImpl : KTVApi, IMusicContentCenterEventHandler, IMediaPlayerObserver
856
857
token,
857
858
rtcConnection,
858
859
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
869
869
}
870
+ onJoinChorus2ndChannelCallback(0 )
871
+ mRtcEngine.enableAudioVolumeIndicationEx(50 , 10 , true , rtcConnection)
872
+ }
870
873
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
878
880
}
881
+ }
879
882
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" )
889
891
}
892
+ }
890
893
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
+ }
895
898
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) }
903
905
}
904
- )
906
+ }
907
+ handlerEx = handler
908
+ mRtcEngine.addHandlerEx(handler, rtcConnection)
905
909
906
910
if (ret != 0 ) {
907
911
Log .e(TAG , " joinChorus2ndChannel failed: $ret " )
@@ -914,6 +918,7 @@ class KTVApiImpl : KTVApi, IMusicContentCenterEventHandler, IMediaPlayerObserver
914
918
}
915
919
916
920
private fun leaveChorus2ndChannel (role : KTVSingRole ) {
921
+ mRtcEngine.removeHandlerEx(handlerEx, subChorusConnection)
917
922
if (role == KTVSingRole .LeadSinger ) {
918
923
mRtcEngine.leaveChannelEx(subChorusConnection)
919
924
} else if (role == KTVSingRole .CoSinger ) {
0 commit comments