> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stmlink.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> 对外开放的服务端接口有两组前缀，都用同一套鉴权：`/server/v1/...`（SRTC 与 SMeeting 的主接口）和 `/stm/srvapi/v1/...`（SMeeting 的用户体系，服务端极简对接会用到）。鉴权是 app_id + nonce + timestamp + signature 四个请求头，用 app_key 做 HMAC-SHA256 签名，只能从业务方自己的后端调用。除这两组前缀外的接口均为内部接口，不要建议客户调用。 Public server APIs use two path prefixes with the same authentication: `/server/v1/...` (the main APIs of both SRTC and SMeeting) and `/stm/srvapi/v1/...` (the SMeeting user system, used by server-side low-code integration). Authenticate with four request headers, app_id + nonce + timestamp + signature, where signature is HMAC-SHA256 keyed with app_key; call these APIs only from the customer's own backend. Any other path is internal: never suggest calling it.
> app_key 是服务端密钥，绝不能出现在客户端代码、前端配置或移动 App 里。客户端加入频道用的 token 必须由业务方后端签发后下发（SRTC 走 `/server/v1/channel/grant`，SMeeting 走 `/stm/srvapi/v1/member/grant`）。 app_key is a server-side secret and must never appear in client code, frontend config, or a mobile app. The token a client uses to join must be issued by the customer's backend and passed down to the client (SRTC: `/server/v1/channel/grant`; SMeeting: `/stm/srvapi/v1/member/grant`).
> SRTC 与 SMeeting 是上下两层不同的产品，术语不通用：SRTC 是音视频底座，说「频道 channel」「加入 / 退出」；SMeeting 建在 SRTC 之上，说「房间 room」「会议 meeting」「进入 / 退出」。回答时按用户所在的层用对应术语，不要把「房间」「会议」安到 SRTC 的接口上，也不要用「频道」「加入 / 离开」描述 SMeeting 的概念（接口标识符原样保留）。 SRTC and SMeeting are two separate layers with different terminology. SRTC is the audio/video foundation: it has channels, and users join and leave a channel. SMeeting is built on top of SRTC: it has rooms and meetings, and members enter and exit a meeting. Answer in the terms of the layer the user is working with: never apply "room" or "meeting" to SRTC APIs, and never describe SMeeting concepts in prose with "channel", "join", or "leave" (API identifiers such as `force_join` keep their literal names).
> 同一能力在各端 SDK 里的包名、类名、方法名并不相同。写示例代码时请使用文档中该端自己的 API，不要把一个端的写法套到另一个端上。苹果平台每个产品都有两套 SDK（Swift 原生与 Objective-C），两套 API 不能混用。 Package, class, and method names differ between platform SDKs for the same capability. In sample code, use the API documented for that platform; never carry one platform's code over to another. On Apple platforms each product ships two SDKs (native Swift and Objective-C) whose APIs must not be mixed.

# AudioRouterManager

> Android API for switching audio output routes between the speaker, earpiece, wired headset, and Bluetooth headset: getting the singleton, auto-switch policies, manual switching, audio focus, device queries, and callbacks. Read when controlling audio output devices on Android.

`AudioRouterManager` manages audio output routing between the speaker / earpiece / wired headset / Bluetooth headset. This page is the API reference; for the full initialization order, auto-switch policies, and best practices, see [Audio routing](/en/rtc/android/advanced/audio-routing).

## Getting and releasing

Get the singleton through `RTCEngine`; don't create it yourself with `new`:

```kotlin theme={null}
val audioRouterManager = rtcEngine.getAudioRouterManager()
// ...
rtcEngine.releaseAudioRouterManager()
```

## Instance methods

### setAudioRouterCalllback(callback)

```java theme={null}
public void setAudioRouterCalllback(AudioRouterCallback callback)
```

Description: Sets the audio routing callback listener.\
Parameters:

* `callback`: `AudioRouterCallback`, the route change callback implementation.

Returns: None (`void`).

> The method name is `setAudioRouterCalllback` (`Calllback` has 3 `l`s); call it exactly as spelled in the source.

### setAutoChangeAudioRouter(isAutoChange)

```java theme={null}
public void setAutoChangeAudioRouter(boolean isAutoChange)
```

Description: Sets whether to switch audio routes automatically (simple version). Equivalent to `setAutoChangeAudioRouter(isAutoChange, false, false)`, meaning the earpiece has priority over the speaker and a Bluetooth headset has priority over a wired headset.\
Parameters:

* `isAutoChange`: `boolean`; `true` lets the SDK choose the route automatically, `false` only listens without switching automatically.

Returns: None (`void`).

### setAutoChangeAudioRouter(isAutoChange, isPrioritySpeaker, isPriorityWiredEarphone)

```java theme={null}
public void setAutoChangeAudioRouter(boolean isAutoChange, boolean isPrioritySpeaker, boolean isPriorityWiredEarphone)
```

Description: Sets the auto-switch policy (full version).\
Parameters:

* `isAutoChange`: `boolean`, whether to switch routes automatically.
* `isPrioritySpeaker`: `boolean`; `true` gives the speaker priority over the earpiece, `false` gives the earpiece priority over the speaker.
* `isPriorityWiredEarphone`: `boolean`; `true` gives a wired headset priority over a Bluetooth headset, `false` gives a Bluetooth headset priority over a wired headset.

Returns: None (`void`).

### setMode(mode)

```java theme={null}
public void setMode(int mode)
```

Description: Sets the audio mode. Values follow `AudioManager` (such as `MODE_IN_COMMUNICATION`). On Android 6.0+, `init()` doesn't set the mode automatically, so call it again every time you switch app scenarios.\
Parameters:

* `mode`: `int`, the `AudioManager` audio mode.

Returns: None (`void`).

### init()

```java theme={null}
public void init()
```

Description: Starts audio route monitoring. Call it after getting the instance and setting the callback and policy.\
Parameters: None.\
Returns: None (`void`).

### switchAudioRouter(type)

```java theme={null}
public void switchAudioRouter(AudioOutputDeviceType type)
```

Description: Manually switches to the specified output device. Passing `UN_KNOW` reselects the most suitable route according to the current auto-switch policy.\
Parameters:

* `type`: `AudioOutputDeviceType`, the target output device type.

Returns: None (`void`).

### release(changeMode)

```java theme={null}
public void release(boolean changeMode)
```

Description: Releases audio routing resources, stops monitoring, and unregisters the callback.\
Parameters:

* `changeMode`: `boolean`; `true` restores the audio mode to `MODE_NORMAL` and switches back to the speaker on release; `false` doesn't restore the mode.

Returns: None (`void`).

> `rtcEngine.releaseAudioRouterManager()` calls `release(true)` internally.

### getExitAudioOutputDevices()

```java theme={null}
public HashMap<AudioOutputDeviceType, AudioDeviceInfo> getExitAudioOutputDevices()
```

Description: Gets the set of output devices currently present (selectable).\
Parameters: None.\
Returns: `HashMap<AudioOutputDeviceType, AudioDeviceInfo>`, a map from device type to device info.

### getActiveAudioOutputDevice()

```java theme={null}
public Pair<AudioOutputDeviceType, AudioDeviceInfo> getActiveAudioOutputDevice()
```

Description: Gets the output device currently in effect.\
Parameters: None.\
Returns: `Pair<AudioOutputDeviceType, AudioDeviceInfo>`; `first` is the device type, `second` is the device info.

### getAudioRouterCallback()

```java theme={null}
public AudioRouterCallback getAudioRouterCallback()
```

Description: Gets the currently set route callback.\
Parameters: None.\
Returns: `AudioRouterCallback`, the current callback instance; may be `null`.

### getAudioManager()

```java theme={null}
public AudioManager getAudioManager()
```

Description: Gets the system `AudioManager` held internally.\
Parameters: None.\
Returns: `AudioManager`.

### requestAudioFocus()

```java theme={null}
public int requestAudioFocus()
```

Description: Requests audio focus.\
Parameters: None.\
Returns: `int`, the request result (same as the return value of the system `AudioManager.requestAudioFocus`).

### releaseAudioFocus()

```java theme={null}
public int releaseAudioFocus()
```

Description: Releases audio focus.\
Parameters: None.\
Returns: `int`, the release result.

### setFocusChangeListener(listener)

```java theme={null}
public void setFocusChangeListener(AudioManager.OnAudioFocusChangeListener listener)
```

Description: Sets an external audio focus change listener.\
Parameters:

* `listener`: `AudioManager.OnAudioFocusChangeListener`, the focus change listener.

Returns: None (`void`).

## Static methods

### getValidBluetoothName(curName, context, callback)

```java theme={null}
public static synchronized void getValidBluetoothName(String curName, Context context, ValidBluetoothNameCallback callback)
```

Description: Corrects inaccurate Bluetooth names that some device models return from `AudioDeviceInfo.getProductName()`. On Android 12+, mind the `BLUETOOTH_CONNECT` permission.\
Parameters:

* `curName`: `String`, the Bluetooth name currently obtained.
* `context`: `Context`, the context.
* `callback`: `ValidBluetoothNameCallback`, the callback for the corrected name.

Returns: None (`void`).

## Enum AudioOutputDeviceType

| Enum value | Description |
| - | - |
| `UN_KNOW` | Unknown / triggers automatic selection according to the policy. |
| `SPEAKER` | Speaker. |
| `EARPIECE` | Earpiece. |
| `WIRED_EARPHONE` | Wired headset. |
| `BLUETOOTH_HEADSET` | Bluetooth headset. |

## Callback interfaces

### AudioRouterCallback

```java theme={null}
public interface AudioRouterCallback {
    void exitOutputDeviceChange(HashMap<AudioOutputDeviceType, AudioDeviceInfo> audioOutputDevices);
    void activeOutputDeviceChange(Pair<AudioOutputDeviceType, AudioDeviceInfo> audioOutputDevice);
    void onAudioBecomingNoisy();
}
```

* `exitOutputDeviceChange`: The list of currently "selectable" output devices changed (headset plugged in or removed, Bluetooth connected or disconnected, and so on).
* `activeOutputDeviceChange`: The output device "actually in effect" changed; use this to show the current device in the UI.
* `onAudioBecomingNoisy`: The system may produce noise after a route switch (for example, when a headset is unplugged and audio switches to the speaker); you can pause playback or lower the volume here.

### ValidBluetoothNameCallback

```java theme={null}
public interface ValidBluetoothNameCallback {
    void onValidBluetoothName(String name);
}
```

* `onValidBluetoothName`: Returns the corrected Bluetooth device name.
