Added in API level 12
Deprecated in API level 31

AudioGroup

open class AudioGroup
kotlin.Any
   ↳ android.net.rtp.AudioGroup

An AudioGroup is an audio hub for the speaker, the microphone, and AudioStreams. Each of these components can be logically turned on or off by calling setMode(int) or RtpStream#setMode(int). The AudioGroup will go through these components and process them one by one within its execution loop. The loop consists of four steps. First, for each AudioStream not in RtpStream#MODE_SEND_ONLY, decodes its incoming packets and stores in its buffer. Then, if the microphone is enabled, processes the recorded audio and stores in its buffer. Third, if the speaker is enabled, mixes all AudioStream buffers and plays back. Finally, for each AudioStream not in RtpStream#MODE_RECEIVE_ONLY, mixes all other buffers and sends back the encoded packets. An AudioGroup does nothing if there is no AudioStream in it.

Few things must be noticed before using these classes. The performance is highly related to the system load and the network bandwidth. Usually a simpler AudioCodec costs fewer CPU cycles but requires more network bandwidth, and vise versa. Using two AudioStreams at the same time doubles not only the load but also the bandwidth. The condition varies from one device to another, and developers should choose the right combination in order to get the best result.

It is sometimes useful to keep multiple AudioGroups at the same time. For example, a Voice over IP (VoIP) application might want to put a conference call on hold in order to make a new call but still allow people in the conference call talking to each other. This can be done easily using two AudioGroups, but there are some limitations. Since the speaker and the microphone are globally shared resources, only one AudioGroup at a time is allowed to run in a mode other than MODE_ON_HOLD. The others will be unable to acquire these resources and fail silently.

Using this class requires android.Manifest.permission#RECORD_AUDIO permission. Developers should set the audio mode to AudioManager#MODE_IN_COMMUNICATION using AudioManager#setMode(int) and change it back when none of the AudioGroups is in use.

Summary

Constants
static Int

This mode is similar to MODE_NORMAL except the echo suppression is enabled.

static Int

This mode is similar to MODE_NORMAL except the microphone is disabled.

static Int

This mode indicates that the speaker, the microphone, and all AudioStreams in the group are enabled.

static Int

This mode is similar to MODE_NORMAL except the speaker and the microphone are both disabled.

Public constructors

Creates an empty AudioGroup.

AudioGroup(context: Context)

Creates an empty AudioGroup.

Public methods
open Unit

Removes every AudioStream in this group.

open Int

Returns the current mode.

open Array<AudioStream!>!

Returns the AudioStreams in this group.

open Unit
sendDtmf(event: Int)

Sends a DTMF digit to every AudioStream in this group.

open Unit
setMode(mode: Int)

Changes the current mode.

Protected methods
open Unit

Constants

MODE_ECHO_SUPPRESSION

Added in API level 12
static val MODE_ECHO_SUPPRESSION: Int

Deprecated: Deprecated in Java.

This mode is similar to MODE_NORMAL except the echo suppression is enabled. It should be only used when the speaker phone is on.

Value: 3

MODE_MUTED

Added in API level 12
static val MODE_MUTED: Int

Deprecated: Deprecated in Java.

This mode is similar to MODE_NORMAL except the microphone is disabled.

Value: 1

MODE_NORMAL

Added in API level 12
static val MODE_NORMAL: Int

Deprecated: Deprecated in Java.

This mode indicates that the speaker, the microphone, and all AudioStreams in the group are enabled. First, the packets received from the streams are decoded and mixed with the audio recorded from the microphone. Then, the results are played back to the speaker, encoded and sent back to each stream.

Value: 2

MODE_ON_HOLD

Added in API level 12
static val MODE_ON_HOLD: Int

Deprecated: Deprecated in Java.

This mode is similar to MODE_NORMAL except the speaker and the microphone are both disabled.

Value: 0

Public constructors

AudioGroup

Added in API level 12
AudioGroup()

Deprecated: Replaced by AudioGroup(android.content.Context)

Creates an empty AudioGroup.

AudioGroup

Added in API level 12
AudioGroup(context: Context)

Creates an empty AudioGroup.

Parameters
context Context: Context the group belongs to This value cannot be null.

Public methods

clear

Added in API level 12
open fun clear(): Unit

Deprecated: Deprecated in Java.

Removes every AudioStream in this group.

getMode

Added in API level 12
open fun getMode(): Int

Deprecated: Deprecated in Java.

Returns the current mode.

getStreams

Added in API level 12
open fun getStreams(): Array<AudioStream!>!

Deprecated: Deprecated in Java.

Returns the AudioStreams in this group.

sendDtmf

Added in API level 12
open fun sendDtmf(event: Int): Unit

Deprecated: Deprecated in Java.

Sends a DTMF digit to every AudioStream in this group. Currently only event 0 to 15 are supported.

Exceptions
java.lang.IllegalArgumentException if the event is invalid.

setMode

Added in API level 12
open fun setMode(mode: Int): Unit

Deprecated: Deprecated in Java.

Changes the current mode. It must be one of MODE_ON_HOLD, MODE_MUTED, MODE_NORMAL, and MODE_ECHO_SUPPRESSION.

Parameters
mode Int: The mode to change to.
Exceptions
java.lang.IllegalArgumentException if the mode is invalid.

Protected methods

finalize

Added in API level 12
protected open fun finalize(): Unit

Deprecated: Deprecated in Java.

Exceptions
java.lang.Throwable the Exception raised by this method