human: 如何处理七牛云的实时音视频QNClientEventListener

gpt: [实时音视频](https://developer.qiniu.com/rtc) > API 文档 > Android
>QNClientEventListener

#  QNClientEventListener

最近更新时间: 2023-10-25 14:47:22

[QNRTCClient](https://developer.qiniu.com/rtc/8643/QNClientEventListener/8684/QNRTCClient)
事件回调接口，可在
[QNRTC.createClient](https://developer.qiniu.com/rtc/8643/QNClientEventListener/8732)
接口中传入。

Index

Core Methods

  * onConnectionStateChanged
  * onUserJoined
  * onUserReconnecting
  * onUserReconnected
  * onUserLeft
  * onUserPublished
  * onUserUnpublished
  * onSubscribed
  * onMessageReceived
  * onMediaRelayStateChanged
  * onUserVolumeIndication

Core Methods

onConnectionStateChanged

  * void onConnectionStateChanged([QNConnectionState](https://developer.qiniu.com/rtc/8643/QNClientEventListener/8645/QNConnectionState) state, @Nullable [QNConnectionDisconnectedInfo](https://developer.qiniu.com/rtc/8643/QNClientEventListener/8644/QNConnectionDisconnectedInfo) info)
  * 当房间状态改变时会触发此回调

Parameters

    * state: [QNConnectionState](https://developer.qiniu.com/rtc/8643/QNClientEventListener/8645/QNConnectionState)

当前连接状态

    * info: [QNConnectionDisconnectedInfo](https://developer.qiniu.com/rtc/8643/QNClientEventListener/8644/QNConnectionDisconnectedInfo)

连接断开时，可通过 info 获取连接断开的原因

onUserJoined

  * void onUserJoined(String remoteUserID, String userData)
  * 当远端用户加入房间时会触发此回调

Parameters

    * remoteUserID: String 

用户 ID

    * userData: String 

用户信息

onUserReconnecting

  * void onUserReconnecting(String remoteUserID)
  * 当远端用户进入重连时会触发此回调

Parameters

    * remoteUserID: String 

用户 ID

onUserReconnected

  * void onUserReconnected(String remoteUserID)
  * 当远端用户重连成功时会触发此回调

Parameters

    * remoteUserID: String 

用户 ID

onUserLeft

  * void onUserLeft(String remoteUserID)
  * 当远端用户离开房间时会触发此回调

Parameters

    * remoteUserID: String 

用户 ID

onUserPublished

  * void onUserPublished(String remoteUserID, List<[QNRemoteTrack](https://developer.qiniu.com/rtc/8643/QNClientEventListener/8676/QNRemoteTrack)> trackList)
  * 当远端 Track 发布时会触发此回调

Parameters

    * remoteUserID: String 

用户 ID

    * trackList: List<[QNRemoteTrack](https://developer.qiniu.com/rtc/8643/QNClientEventListener/8676/QNRemoteTrack)>

远端发布的 Track 列表

onUserUnpublished

  * void onUserUnpublished(String remoteUserID, List<[QNRemoteTrack](https://developer.qiniu.com/rtc/8643/QNClientEventListener/8676/QNRemoteTrack)> trackList)
  * 当远端 Track 取消发布时会触发此回调

Parameters

    * remoteUserID: String 

用户 ID

    * trackList: List<[QNRemoteTrack](https://developer.qiniu.com/rtc/8643/QNClientEventListener/8676/QNRemoteTrack)>

远端取消发布的 Track 列表

onSubscribed

  * void onSubscribed(String remoteUserID, List<[QNRemoteAudioTrack](https://developer.qiniu.com/rtc/8643/QNClientEventListener/8674/QNRemoteAudioTrack)> remoteAudioTracks, List<[QNRemoteVideoTrack](https://developer.qiniu.com/rtc/8643/QNClientEventListener/8680/QNRemoteVideoTrack)> remoteVideoTracks)
  * 当订阅 Track 成功时会触发此回调

手动订阅和自动订阅均会通过此回调通知到应用上层

Parameters

    * remoteUserID: String 

用户 ID

    * remoteAudioTracks: List<[QNRemoteAudioTrack](https://developer.qiniu.com/rtc/8643/QNClientEventListener/8674/QNRemoteAudioTrack)>

订阅成功的音频 Track 列表

    * remoteVideoTracks: List<[QNRemoteVideoTrack](https://developer.qiniu.com/rtc/8643/QNClientEventListener/8680/QNRemoteVideoTrack)>

订阅成功的视频 Track 列表

onMessageReceived

  * void onMessageReceived([QNCustomMessage](https://developer.qiniu.com/rtc/8643/QNClientEventListener/8648/QNCustomMessage) message)
  * 当收到自定义消息时发此回调

Parameters

    * message: [QNCustomMessage](https://developer.qiniu.com/rtc/8643/QNClientEventListener/8648/QNCustomMessage)

消息

onMediaRelayStateChanged

  * void onMediaRelayStateChanged(String relayRoom, [QNMediaRelayState](https://developer.qiniu.com/rtc/8643/QNClientEventListener/10168/QNMediaRelayState) state)
  * > 跨房媒体转发状态变更通知，非主动调用触发，由目标房间状态变化引起此通知
>
> 目前仅当目标房间关闭时，会触发此通知

Parameters

    * relayRoom: String 

发生状态变化的房间名

    * state: [QNMediaRelayState](https://developer.qiniu.com/rtc/8643/QNClientEventListener/10168/QNMediaRelayState)

新状态，当前仅可能为
[QNMediaRelayState.ROOM_CLOSED](https://developer.qiniu.com/rtc/8643/QNClientEventListener/10168)

onUserVolumeIndication

  * void onUserVolumeIndication(List<[QNAudioVolumeInfo](https://developer.qiniu.com/rtc/api/12575/QNAudioVolumeInfo)> userVolumeList)
  * 通过 [QNRTCClient.enableAudioVolumeIndication](https://developer.qiniu.com/rtc/8643/QNClientEventListener/8684) 开启音量监测后，将会回调此通知

本地用户的
[QNAudioVolumeInfo](https://developer.qiniu.com/rtc/api/12575/QNAudioVolumeInfo)
中，userID 字段将会保留为空

回调的列表中，按音量由高到低排序，静音用户将不在此列表中体现

Parameters

    * userVolumeList: List<[QNAudioVolumeInfo](https://developer.qiniu.com/rtc/api/12575/QNAudioVolumeInfo)>

音量信息列表

以上内容是否对您有帮助？