# IAgoraMediaRtcRecorderEventHandler 类 (/zh-CN/api-reference/local-server-recording/java/iagoramediartcrecordereventhandler)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

用于接收媒体录制器的回调事件。

<a id="onconnected"></a>
## onConnected [#onconnected]

```java
default void onConnected(String channelId, String userId)
```

SDK 与声网频道连接成功时触发的回调。

#### 参数 [#参数]

| 参数 | 数据类型 | 描述 |
| --- | --- | --- |
| `channelId` | `String` | 频道 ID。 |
| `userId` | `String` | 用户 ID。 |

<a id="ondisconnected"></a>
## onDisconnected [#ondisconnected]

```java
default void onDisconnected(String channelId, String userId, Constants.ConnectionChangedReasonType reason)
```

`CONNECTION_STATE_DISCONNECTED(1)` 状态时触发的回调。

当 SDK 与声网频道的连接状态变为 `CONNECTION_STATE_DISCONNECTED(1)` 时触发该回调。

#### 参数 [#参数-1]

| 参数 | 数据类型 | 描述 |
| --- | --- | --- |
| `channelId` | `String` | 频道 ID。 |
| `userId` | `String` | 用户 ID。 |
| `reason` | `Constants.ConnectionChangedReasonType` | 连接状态变化的原因，详见 [`ConnectionChangedReasonType`](/zh-CN/api-reference/local-server-recording/java/enum#connectionchangedreasontype)。 |

<a id="onreconnected"></a>
## onReconnected [#onreconnected]

```java
default void onReconnected(String channelId, String userId, Constants.ConnectionChangedReasonType reason)
```

`CONNECTION_STATE_CONNECTED(3)` 状态恢复时触发的回调。

#### 参数 [#参数-2]

| 参数 | 数据类型 | 描述 |
| --- | --- | --- |
| `channelId` | `String` | 频道 ID。 |
| `userId` | `String` | 用户 ID。 |
| `reason` | `Constants.ConnectionChangedReasonType` | 连接状态变化的原因。详见 [`ConnectionChangedReasonType`](/zh-CN/api-reference/local-server-recording/java/enum#connectionchangedreasontype)。 |

<a id="onconnectionlost"></a>
## onConnectionLost [#onconnectionlost]

```java
default void onConnectionLost(String channelId, String userId)
```

SDK 与声网频道失去连接时触发的回调。

#### 参数 [#参数-3]

| 参数 | 数据类型 | 描述 |
| --- | --- | --- |
| `channelId` | `String` | 频道的 ID。 |
| `userId` | `String` | 用户的 ID。 |

<a id="onuserjoined"></a>
## onUserJoined [#onuserjoined]

```java
default void onUserJoined(String channelId, String userId)
```

远端用户加入频道回调。

#### 参数 [#参数-4]

| 参数 | 数据类型 | 描述 |
| --- | --- | --- |
| `channelId` | `String` | 频道 ID。 |
| `userId` | `String` | 用户 ID。 |

<a id="onuserleft"></a>
## onUserLeft [#onuserleft]

```java
default void onUserLeft(String channelId, String userId, Constants.UserOfflineReasonType reason)
```

[`onUserLeft`](/zh-CN/api-reference/local-server-recording/java/iagoramediartcrecordereventhandler#onuserleft) 回调：远端用户离开频道时触发。

#### 参数 [#参数-5]

| 参数 | 数据类型 | 描述 |
| --- | --- | --- |
| `channelId` | `String` | 频道 ID。 |
| `userId` | `String` | 用户 ID。 |
| `reason` | `Constants.UserOfflineReasonType` | 远端用户离开频道的原因。详见 [`UserOfflineReasonType`](/zh-CN/api-reference/local-server-recording/java/enum#userofflinereasontype)。 |

<a id="onfirstremotevideodecoded"></a>
## onFirstRemoteVideoDecoded [#onfirstremotevideodecoded]

```java
default void onFirstRemoteVideoDecoded(String channelId, String userId, int width, int height, int elapsed)
```

首帧远端视频解码完成回调。

该回调在 SDK 为录制端成功解码远端用户的首帧视频时触发。

#### 参数 [#参数-6]

| 参数 | 数据类型 | 描述 |
| --- | --- | --- |
| `channelId` | `String` | 频道 ID。 |
| `userId` | `String` | 远端用户 ID。 |
| `width` | `int` | 视频流的宽度（像素）。 |
| `height` | `int` | 视频流的高度（像素）。 |
| `elapsed` | `int` | 从用户加入频道到触发该回调的时间（毫秒）。 |

<a id="onfirstremoteaudiodecoded"></a>
## onFirstRemoteAudioDecoded [#onfirstremoteaudiodecoded]

```java
default void onFirstRemoteAudioDecoded(String channelId, String userId, int elapsed)
```

远端音频首帧解码回调。

#### 参数 [#参数-7]

| 参数 | 数据类型 | 描述 |
| --- | --- | --- |
| `channelId` | `String` | 频道 ID。 |
| `userId` | `String` | 发送音频流的远端用户的用户 ID。 |
| `elapsed` | `int` | 从远端用户加入频道到触发该回调的时间（毫秒）。 |

<a id="onaudiovolumeindication"></a>
## onAudioVolumeIndication [#onaudiovolumeindication]

```java
default void onAudioVolumeIndication(String channelId, SpeakVolumeInfo[] speakers, int speakerNumber)
```

[`onAudioVolumeIndication`](/zh-CN/api-reference/local-server-recording/java/iagoramediartcrecordereventhandler#onaudiovolumeindication) 回调：报告哪些用户正在说话、说话者的音量以及本地用户是否在说话。

#### 参数 [#参数-8]

| 参数 | 数据类型 | 描述 |
| --- | --- | --- |
| `channelId` | `String` | 频道 ID。 |
| `speakers` | `SpeakVolumeInfo[]` | 说话者的用户 ID 和音量信息数组。详见 [`SpeakVolumeInfo`](/zh-CN/api-reference/local-server-recording/java/struct#speakvolumeinfo)。 |
| `speakerNumber` | `int` | 说话者的总人数。 |

<a id="onactivespeaker"></a>
## onActiveSpeaker [#onactivespeaker]

```java
default void onActiveSpeaker(String channelId, String userId)
```

检测到活跃发言人时触发的回调。

你可以在 App 中添加相关功能，例如当检测到活跃发言人时，将其头像放大显示。活跃发言人是指在一段时间内以最大音量发言的用户，其用户 ID 会通过该回调返回。

#### 参数 [#参数-9]

| 参数 | 数据类型 | 描述 |
| --- | --- | --- |
| `channelId` | `String` | 频道 ID。 |
| `userId` | `String` | 活跃发言人的用户 ID。`userId` 为 `0` 表示本地用户。 |

<a id="onuservideostatechanged"></a>
## onUserVideoStateChanged [#onuservideostatechanged]

```java
default void onUserVideoStateChanged(String channelId, String userId, Constants.RemoteVideoState state, Constants.RemoteVideoStateReason reason, int elapsed)
```

远端视频状态发生改变回调。

#### 参数 [#参数-10]

| 参数 | 数据类型 | 描述 |
| --- | --- | --- |
| `channelId` | `String` | 频道 ID。 |
| `userId` | `String` | 远端用户 ID，其视频状态发生了变化。 |
| `state` | `Constants.RemoteVideoState` | 当前的视频状态，详见 [`RemoteVideoState`](/zh-CN/api-reference/local-server-recording/java/enum#remotevideostate)。 |
| `reason` | `Constants.RemoteVideoStateReason` | 状态变化的原因，详见 [`RemoteVideoStateReason`](/zh-CN/api-reference/local-server-recording/java/enum#remotevideostatereason)。 |
| `elapsed` | `int` | 从该用户加入频道到触发该回调的时间（毫秒）。 |

<a id="onuseraudiostatechanged"></a>
## onUserAudioStateChanged [#onuseraudiostatechanged]

```java
default void onUserAudioStateChanged(String channelId, String userId, Constants.RemoteAudioState state, Constants.RemoteAudioStateReason reason, int elapsed)
```

远端用户音频状态发生变化回调。

#### 参数 [#参数-11]

| 参数 | 数据类型 | 描述 |
| --- | --- | --- |
| `channelId` | `String` | 频道 ID。 |
| `userId` | `String` | 音频状态发生变化的远端用户 ID。 |
| `state` | `Constants.RemoteAudioState` | 当前的音频状态，详见 [`RemoteAudioState`](/zh-CN/api-reference/local-server-recording/java/enum#remoteaudiostate)。 |
| `reason` | `Constants.RemoteAudioStateReason` | 状态变化的原因，详见 [`RemoteAudioStateReason`](/zh-CN/api-reference/local-server-recording/java/enum#remoteaudiostatereason)。 |
| `elapsed` | `int` | 从该用户加入声网频道到触发该回调的时间（毫秒）。 |

<a id="onremotevideostats"></a>
## onRemoteVideoStats [#onremotevideostats]

```java
default void onRemoteVideoStats(String channelId, String userId, RemoteVideoStatistics stats)
```

远端视频统计信息回调。

该回调在接收到远端视频流并统计完成后被触发。

#### 参数 [#参数-12]

| 参数 | 数据类型 | 描述 |
| --- | --- | --- |
| `channelId` | `String` | 频道 ID。 |
| `userId` | `String` | 远端用户的 ID。 |
| `stats` | `RemoteVideoStatistics` | 远端视频的统计信息。详见 [`RemoteVideoStatistics`](/zh-CN/api-reference/local-server-recording/java/struct#remotevideostatistics)。 |

<a id="onremoteaudiostats"></a>
## onRemoteAudioStats [#onremoteaudiostats]

```java
default void onRemoteAudioStats(String channelId, String userId, RemoteAudioStatistics stats)
```

远端音频统计信息回调。

#### 参数 [#参数-13]

| 参数 | 数据类型 | 描述 |
| --- | --- | --- |
| `channelId` | `String` | 频道 ID。 |
| `userId` | `String` | 远端用户的 ID。 |
| `stats` | `RemoteAudioStatistics` | 远端音频的统计信息。详见 [`RemoteAudioStatistics`](/zh-CN/api-reference/local-server-recording/java/struct#remoteaudiostatistics)。 |

<a id="onrecorderstatechanged"></a>
## onRecorderStateChanged [#onrecorderstatechanged]

```java
default void onRecorderStateChanged(String channelId, String userId, Constants.RecorderState state, Constants.RecorderReasonCode reason, String fileName)
```

本地音视频录制状态发生变化回调。

该回调用于报告当前的录制状态及其变化原因。

#### 参数 [#参数-14]

| 参数 | 数据类型 | 描述 |
| --- | --- | --- |
| `channelId` | `String` | 频道名。 |
| `userId` | `String` | 用户 ID。 |
| `state` | `Constants.RecorderState` | 当前录制状态，详见 [`RecorderState`](/zh-CN/api-reference/local-server-recording/java/enum#recorderstate)。 |
| `reason` | `Constants.RecorderReasonCode` | 状态变化的原因，详见 [`RecorderReasonCode`](/zh-CN/api-reference/local-server-recording/java/enum#recorderreasoncode)。 |
| `fileName` | `String` | 录制流的文件名。 |

<a id="onrecorderinfoupdated"></a>
## onRecorderInfoUpdated [#onrecorderinfoupdated]

```java
default void onRecorderInfoUpdated(String channelId, String userId, RecorderInfo info)
```

录制信息更新回调。

在你成功注册该回调并启用本地音视频录制后，SDK 会根据设置的 `recorderInfoUpdateInterval` 值周期性地触发该回调。

#### 参数 [#参数-15]

| 参数 | 数据类型 | 描述 |
| --- | --- | --- |
| `channelId` | `String` | 频道名。 |
| `userId` | `String` | 用户 ID。 |
| `info` | `RecorderInfo` | 录制文件的信息，详见 [`RecorderInfo`](/zh-CN/api-reference/local-server-recording/java/struct#recorderinfo)。 |

<a id="onencryptionerror"></a>
## onEncryptionError [#onencryptionerror]

```java
default void onEncryptionError(String channelId, Constants.EncryptionErrorType errorType)
```

加密错误发生时触发的回调。

#### 参数 [#参数-16]

| 参数 | 数据类型 | 描述 |
| --- | --- | --- |
| `channelId` | `String` | 频道 ID。 |
| `errorType` | `Constants.EncryptionErrorType` | 加密错误类型。详见 [`EncryptionErrorType`](/zh-CN/api-reference/local-server-recording/java/enum#encryptionerrortype)。 |

<a id="onerror"></a>
## onError [#onerror]

```java
default void onError(String channelId, Constants.ErrorCodeType error, String message)
```

错误回调。

该回调用于报告错误码和错误信息。

#### 参数 [#参数-17]

| 参数 | 数据类型 | 描述 |
| --- | --- | --- |
| `channelId` | `String` | 频道 ID。 |
| `error` | `Constants.ErrorCodeType` | 错误码。详见 [`ErrorCodeType`](/zh-CN/api-reference/local-server-recording/java/enum#errorcodetype)。 |
| `message` | `String` | 错误信息。 |

<a id="ontokenprivilegewillexpire"></a>
## onTokenPrivilegeWillExpire [#ontokenprivilegewillexpire]

```java
default void onTokenPrivilegeWillExpire(String channelId, String token)
```

 Token 权限即将在 30 秒后过期时触发的回调。

收到该回调后，你必须在服务器上生成新的 Token，并调用 [`renewToken`](/zh-CN/api-reference/local-server-recording/java/agoramediartcrecorder.java#renewtoken) 方法更新 Token。

#### 参数 [#参数-18]

| 参数 | 数据类型 | 描述 |
| --- | --- | --- |
| `channelId` | `String` | 频道 ID。 |
| `token` | `String` | 即将在 30 秒后过期的 Token。 |

<a id="ontokenprivilegedidexpire"></a>
## onTokenPrivilegeDidExpire [#ontokenprivilegedidexpire]

```java
default void onTokenPrivilegeDidExpire(String channelId)
```

 Token 过期回调。

收到该回调后，你必须在你的服务器上生成一个新的 Token，并调用 [`renewToken`](/zh-CN/api-reference/local-server-recording/java/agoramediartcrecorder.java#renewtoken) 方法进行更新。

#### 参数 [#参数-19]

| 参数 | 数据类型 | 描述 |
| --- | --- | --- |
| `channelId` | `String` | 频道 ID。 |

<a id="onvideosizechanged"></a>
## onVideoSizeChanged [#onvideosizechanged]

```java
default void onVideoSizeChanged(String channelId, String userId, int width, int height, int rotation)
```

远端视频尺寸发生变化回调。

#### 参数 [#参数-20]

| 参数 | 数据类型 | 描述 |
| --- | --- | --- |
| `channelId` | `String` | 频道 ID。 |
| `userId` | `String` | 远端用户 ID。 |
| `width` | `int` | 视频流的宽度。 |
| `height` | `int` | 视频流的高度。 |
| `rotation` | `int` | 视频流的旋转角度。 |
