Added in [API level 12](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/net/rtp/AudioGroup#constants) \| [Ctors](https://developer.android.com/reference/android/net/rtp/AudioGroup#pubctors) \| [Methods](https://developer.android.com/reference/android/net/rtp/AudioGroup#pubmethods) \| [Protected Methods](https://developer.android.com/reference/android/net/rtp/AudioGroup#promethods) \| [Inherited Methods](https://developer.android.com/reference/android/net/rtp/AudioGroup#inhmethods)

# AudioGroup

*** ** * ** ***

` public class AudioGroup `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.net.rtp.AudioGroup |

<br />

*** ** * ** ***

<br />

**This class was deprecated in API level 31.**   
`https://developer.android.com/reference/android/net/sip/SipManager` and associated classes are no longer supported and should not be used as the basis of future VOIP apps.

An AudioGroup is an audio hub for the speaker, the microphone, and `https://developer.android.com/reference/android/net/rtp/AudioStream`s. Each of these components can be logically turned on or off by calling `https://developer.android.com/reference/android/net/rtp/AudioGroup#setMode(int)` or `https://developer.android.com/reference/android/net/rtp/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 `https://developer.android.com/reference/android/net/rtp/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 `https://developer.android.com/reference/android/net/rtp/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 `https://developer.android.com/reference/android/net/rtp/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 `https://developer.android.com/reference/android/net/rtp/AudioGroup#MODE_ON_HOLD`. The others will be unable to acquire these resources and fail silently.

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

<br />

**See also:**

- `https://developer.android.com/reference/android/net/rtp/AudioStream`

## Summary

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/net/rtp/AudioGroup#MODE_ECHO_SUPPRESSION` This mode is similar to `https://developer.android.com/reference/android/net/rtp/AudioGroup#MODE_NORMAL` except the echo suppression is enabled. |
| `int` | `https://developer.android.com/reference/android/net/rtp/AudioGroup#MODE_MUTED` This mode is similar to `https://developer.android.com/reference/android/net/rtp/AudioGroup#MODE_NORMAL` except the microphone is disabled. |
| `int` | `https://developer.android.com/reference/android/net/rtp/AudioGroup#MODE_NORMAL` This mode indicates that the speaker, the microphone, and all `https://developer.android.com/reference/android/net/rtp/AudioStream`s in the group are enabled. |
| `int` | `https://developer.android.com/reference/android/net/rtp/AudioGroup#MODE_ON_HOLD` This mode is similar to `https://developer.android.com/reference/android/net/rtp/AudioGroup#MODE_NORMAL` except the speaker and the microphone are both disabled. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/net/rtp/AudioGroup#AudioGroup()() ` *This constructor is deprecated. Replaced by `https://developer.android.com/reference/android/net/rtp/AudioGroup#AudioGroup(android.content.Context)`* |
| ` https://developer.android.com/reference/android/net/rtp/AudioGroup#AudioGroup(android.content.Context)(https://developer.android.com/reference/android/content/Context context) ` Creates an empty AudioGroup. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/net/rtp/AudioGroup#clear()() ` Removes every `https://developer.android.com/reference/android/net/rtp/AudioStream` in this group. |
| ` int` | ` https://developer.android.com/reference/android/net/rtp/AudioGroup#getMode()() ` Returns the current mode. |
| ` https://developer.android.com/reference/android/net/rtp/AudioStream` | ` https://developer.android.com/reference/android/net/rtp/AudioGroup#getStreams()() ` Returns the `https://developer.android.com/reference/android/net/rtp/AudioStream`s in this group. |
| ` void` | ` https://developer.android.com/reference/android/net/rtp/AudioGroup#sendDtmf(int)(int event) ` Sends a DTMF digit to every `https://developer.android.com/reference/android/net/rtp/AudioStream` in this group. |
| ` void` | ` https://developer.android.com/reference/android/net/rtp/AudioGroup#setMode(int)(int mode) ` Changes the current mode. |

| ### Protected methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/net/rtp/AudioGroup#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Constants

### MODE_ECHO_SUPPRESSION

Added in [API level 12](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int MODE_ECHO_SUPPRESSION
```

This mode is similar to `https://developer.android.com/reference/android/net/rtp/AudioGroup#MODE_NORMAL` except the echo suppression is enabled. It should be only used when the speaker phone is on.

<br />

Constant Value: 3 (0x00000003)

### MODE_MUTED

Added in [API level 12](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int MODE_MUTED
```

This mode is similar to `https://developer.android.com/reference/android/net/rtp/AudioGroup#MODE_NORMAL` except the microphone is disabled.

<br />

Constant Value: 1 (0x00000001)

### MODE_NORMAL

Added in [API level 12](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int MODE_NORMAL
```

This mode indicates that the speaker, the microphone, and all `https://developer.android.com/reference/android/net/rtp/AudioStream`s 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.

<br />

Constant Value: 2 (0x00000002)

### MODE_ON_HOLD

Added in [API level 12](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int MODE_ON_HOLD
```

This mode is similar to `https://developer.android.com/reference/android/net/rtp/AudioGroup#MODE_NORMAL` except the speaker and the microphone are both disabled.

<br />

Constant Value: 0 (0x00000000)

## Public constructors

### AudioGroup

Added in [API level 12](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public AudioGroup ()
```

<br />

**This constructor is deprecated.**   

Replaced by `https://developer.android.com/reference/android/net/rtp/AudioGroup#AudioGroup(android.content.Context)`

Creates an empty AudioGroup.

<br />

### AudioGroup

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public AudioGroup (Context context)
```

Creates an empty AudioGroup.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: Context the group belongs to. This value cannot be `null`. <br /> |

## Public methods

### clear

Added in [API level 12](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void clear ()
```

Removes every `https://developer.android.com/reference/android/net/rtp/AudioStream` in this group.

<br />

### getMode

Added in [API level 12](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getMode ()
```

Returns the current mode.

<br />

| Returns ||
|---|---|
| `int` | <br /> |

### getStreams

Added in [API level 12](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public AudioStream[] getStreams ()
```

Returns the `https://developer.android.com/reference/android/net/rtp/AudioStream`s in this group.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/rtp/AudioStream` | <br /> |

### sendDtmf

Added in [API level 12](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void sendDtmf (int event)
```

Sends a DTMF digit to every `https://developer.android.com/reference/android/net/rtp/AudioStream` in this group. Currently only event `0` to `15` are supported.

<br />

| Parameters ||
|---|---|
| `event` | `int` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the event is invalid. |

### setMode

Added in [API level 12](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setMode (int mode)
```

Changes the current mode. It must be one of `https://developer.android.com/reference/android/net/rtp/AudioGroup#MODE_ON_HOLD`, `https://developer.android.com/reference/android/net/rtp/AudioGroup#MODE_MUTED`, `https://developer.android.com/reference/android/net/rtp/AudioGroup#MODE_NORMAL`, and `https://developer.android.com/reference/android/net/rtp/AudioGroup#MODE_ECHO_SUPPRESSION`.

<br />

| Parameters ||
|---|---|
| `mode` | `int`: The mode to change to. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the mode is invalid. |

## Protected methods

### finalize

Added in [API level 12](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void finalize ()
```

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the `finalize` method to dispose of system resources or to perform other cleanup.

The general contract of `finalize` is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The `finalize` method may take any action, including making this object available again to other threads; the usual purpose of `finalize`, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The `finalize` method of class `Object` performs no special action; it simply returns normally. Subclasses of `Object` may override this definition.

The Java programming language does not guarantee which thread will invoke the `finalize` method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the `finalize` method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The `finalize` method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the `finalize` method causes the finalization of this object to be halted, but is otherwise ignored.

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/Throwable` |   |