Skip to content

AudioDeviceManager

Lejla Solak edited this page Feb 10, 2025 · 3 revisions



setAudioDeviceEventListener(audioDeviceEventListener)

Description

Configures event handler to handle audio device changes events.

Arguments

  • audioDeviceEventListener: AudioDeviceEventListener - An interface that should be implemented in order to properly handle audio device changes.

Returns

  • N/A

Example

private void example() {
    // Obtain the token and initialize the InfobipRTC instance
    String token = obtainToken();
    InfobipRTC infobipRTC = InfobipRTC.getInstance();

    // Get the active application call
    ApplicationCall applicationCall = infobipRTC.getActiveApplicationCall();

    // Get the audio device manager from the application call
    AudioDeviceManager audioDeviceManager = applicationCall.audioDeviceManager();

    // Set the audio device event listener
    audioDeviceManager.setAudioDeviceEventListener(new AudioDeviceEventListener() {
        @Override
        public void onActiveAudioDeviceChanged(@NonNull ActiveAudioDeviceChangedEvent activeAudioDeviceChangedEvent) {
            // Handle the active audio device change event
            String name = activeAudioDeviceChangedEvent.getActiveAudioDevice().getName();
            Log.d("WebRTC", String.format("Active audio device changed, now using %s", name));
        }

        @Override
        public void onAvailableAudioDevicesChanged(@NonNull AvailableAudioDevicesChangedEvent availableAudioDevicesChangedEvent) {
            // Handle the available audio devices change event
            Log.d("WebRTC", "Available audio devices list updated.");
            updateListOfAvailableAudioDevices(availableAudioDevicesChangedEvent.getAvailableAudioDevices());
        }
    });
}



getAudioDeviceEventListener()

Description

Retrieves the event handler for audio device change events.

Arguments

  • none

Returns

Example

// Obtain the token and initialize the InfobipRTC instance
String token = obtainToken();
InfobipRTC infobipRTC = InfobipRTC.getInstance();

// Get the active application call
ApplicationCall applicationCall = infobipRTC.getActiveApplicationCall();

// Get the audio device manager from the application call
AudioDeviceManager audioDeviceManager = applicationCall.audioDeviceManager();

// Get the audio device event listener
AudioDeviceEventListener audioDeviceEventListener = audioDeviceManager.getAudioDeviceEventListener();



getActiveDevice()

Description

Retrieves the active audio device currently in use during the call. It may return null during call initialization. Please note that the active audio device can change if a new device is connected or the current device is disconnected. In such cases, the onActiveAudioDeviceChanged method will be triggered to notify you about the new active device.

Arguments

  • none

Returns

  • AudioDevice - An object representing the currently used audio device.

Example

// Obtain the token and initialize the InfobipRTC instance
String token = obtainToken();
InfobipRTC infobipRTC = InfobipRTC.getInstance();

// Get the active application call
ApplicationCall applicationCall = infobipRTC.getActiveApplicationCall();

// Get the audio device manager from the application call
AudioDeviceManager audioDeviceManager = applicationCall.audioDeviceManager();

// Get the active device
AudioDevice activeDevice = audioDeviceManager.getActiveDevice();



getAvailableAudioDevices()

Description

Retrieves a set of available audio devices sorted by the priority order. Please note that the set of available audio devices can change if a new device is connected or the current device is disconnected. In such cases, the onAvailableAudioDevicesChanged method will be triggered to notify you about the new available devices.

Arguments

  • none

Returns

  • Set<AudioDevice> - A set containing the currently available audio devices sorted by the priority order.

Example

// Obtain the token and initialize the InfobipRTC instance
String token = obtainToken();
InfobipRTC infobipRTC = InfobipRTC.getInstance();

// Get the active application call
ApplicationCall applicationCall = infobipRTC.getActiveApplicationCall();

// Get the audio device manager from the application call
AudioDeviceManager audioDeviceManager = applicationCall.audioDeviceManager();

// Get the available devices
Set<AudioDevice> availableAudioDevices = audioDeviceManager.getAvailableAudioDevices();



selectAudioDevice(audioDevice)

Description

Changes the currently active audio device to the specified audio device. If the selected audio device is available, it becomes the active device. When the call ends, the selected audio device is reset to the default device. Please be aware that the active audio device can be changed if a new device is connected or the current device is disconnected. In such cases, the onActiveAudioDeviceChanged event will be triggered to notify you about the new active device.

Arguments

  • audioDevice: AudioDevice - The audio device to be set as active.

Returns

  • N/A

Throws

  • MissingPermissionsException - This exception is thrown when the required permission is not granted. It contains a descriptive message explaining the issue.

On Android 12 or higher, the BLUETOOTH_CONNECT permission is required. Make sure to grant this permission before making the call. There is no need to request this permission on Android 11 or lower. To understand the required permissions better, refer to our permissions tutorial.

Example

private void example() {
    // Obtain the token and initialize the InfobipRTC instance
    String token = obtainToken();
    InfobipRTC infobipRTC = InfobipRTC.getInstance();

    // Get the active application call
    ApplicationCall applicationCall = infobipRTC.getActiveApplicationCall();

    // Get the audio device manager from the application call
    AudioDeviceManager audioDeviceManager = applicationCall.audioDeviceManager();

    // Get the list of available audio devices
    List<AudioDevice> availableAudioDevices = new ArrayList<>(audioDeviceManager.getAvailableAudioDevices());

    try {
        // Select the first available audio device
        AudioDevice audioDevice = availableAudioDevices.get(0);
        audioDeviceManager.selectAudioDevice(audioDevice);
    } catch (MissingPermissionsException e) {
        Log.e("WebRTC", String.format("Error setting active device: %s", e.getMessage()));
    }
}

Tutorials

Migration guides

Reference documentation

Clone this wiki locally