# AudioStream

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:[Inherited Constants](https://developer.android.com/reference/android/net/rtp/AudioStream#inhconstants)\|[Ctors](https://developer.android.com/reference/android/net/rtp/AudioStream#pubctors)\|[Methods](https://developer.android.com/reference/android/net/rtp/AudioStream#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/net/rtp/AudioStream#inhmethods)  

# AudioStream

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/net/rtp/AudioStream "View this page in Kotlin")\|Java

`
public


class
AudioStream
`  
`


``

extends `[RtpStream](https://developer.android.com/reference/android/net/rtp/RtpStream)`


``


`

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

<br />

*** ** * ** ***

<br />

**This class was deprecated in API level 31.**   
[SipManager](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 AudioStream is a[RtpStream](https://developer.android.com/reference/android/net/rtp/RtpStream)which carrys audio payloads over Real-time Transport Protocol (RTP). Two different classes are developed in order to support various usages such as audio conferencing. An AudioStream represents a remote endpoint which consists of a network mapping and a configured[AudioCodec](https://developer.android.com/reference/android/net/rtp/AudioCodec). On the other side, An[AudioGroup](https://developer.android.com/reference/android/net/rtp/AudioGroup)represents a local endpoint which mixes all the AudioStreams and optionally interacts with the speaker and the microphone at the same time. The simplest usage includes one for each endpoints. For other combinations, developers should be aware of the limitations described in[AudioGroup](https://developer.android.com/reference/android/net/rtp/AudioGroup).

An AudioStream becomes busy when it joins an AudioGroup. In this case most of the setter methods are disabled. This is designed to ease the task of managing native resources. One can always make an AudioStream leave its AudioGroup by calling[join(android.net.rtp.AudioGroup)](https://developer.android.com/reference/android/net/rtp/AudioStream#join(android.net.rtp.AudioGroup))with`null`and put it back after the modification is done.

Using this class requires[Manifest.permission.INTERNET](https://developer.android.com/reference/android/Manifest.permission#INTERNET)permission.

<br />

**See also:**

- [RtpStream](https://developer.android.com/reference/android/net/rtp/RtpStream)
- [AudioGroup](https://developer.android.com/reference/android/net/rtp/AudioGroup)

## Summary

|                                                                                                                                                                                                                                                                                                                                                                                                                             ### Inherited constants                                                                                                                                                                                                                                                                                                                                                                                                                              |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| From class[android.net.rtp.RtpStream](https://developer.android.com/reference/android/net/rtp/RtpStream) |-------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `int` | [MODE_NORMAL](https://developer.android.com/reference/android/net/rtp/RtpStream#MODE_NORMAL) This mode indicates that the stream sends and receives packets at the same time. | | `int` | [MODE_RECEIVE_ONLY](https://developer.android.com/reference/android/net/rtp/RtpStream#MODE_RECEIVE_ONLY) This mode indicates that the stream only receives packets.           | | `int` | [MODE_SEND_ONLY](https://developer.android.com/reference/android/net/rtp/RtpStream#MODE_SEND_ONLY) This mode indicates that the stream only sends packets.                    | |

|                                                                                                                         ### Public constructors                                                                                                                         ||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[AudioStream](https://developer.android.com/reference/android/net/rtp/AudioStream#AudioStream(java.net.InetAddress))`(`[InetAddress](https://developer.android.com/reference/java/net/InetAddress)` address) ` Creates an AudioStream on the given local address. |

|                                                                                                                                                                                         ### Public methods                                                                                                                                                                                          ||
|-------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` `[AudioCodec](https://developer.android.com/reference/android/net/rtp/AudioCodec) | ` `[getCodec](https://developer.android.com/reference/android/net/rtp/AudioStream#getCodec())`() ` Returns the[AudioCodec](https://developer.android.com/reference/android/net/rtp/AudioCodec), or`null`if it is not set.                                                                                      |
| ` int`                                                                              | ` `[getDtmfType](https://developer.android.com/reference/android/net/rtp/AudioStream#getDtmfType())`() ` Returns the RTP payload type for dual-tone multi-frequency (DTMF) digits, or`-1`if it is not enabled.                                                                                                 |
| ` `[AudioGroup](https://developer.android.com/reference/android/net/rtp/AudioGroup) | ` `[getGroup](https://developer.android.com/reference/android/net/rtp/AudioStream#getGroup())`() ` Returns the joined[AudioGroup](https://developer.android.com/reference/android/net/rtp/AudioGroup).                                                                                                         |
| ` final boolean`                                                                    | ` `[isBusy](https://developer.android.com/reference/android/net/rtp/AudioStream#isBusy())`() ` Returns`true`if the stream has already joined an[AudioGroup](https://developer.android.com/reference/android/net/rtp/AudioGroup).                                                                               |
| ` void`                                                                             | ` `[join](https://developer.android.com/reference/android/net/rtp/AudioStream#join(android.net.rtp.AudioGroup))`(`[AudioGroup](https://developer.android.com/reference/android/net/rtp/AudioGroup)` group) ` Joins an[AudioGroup](https://developer.android.com/reference/android/net/rtp/AudioGroup).         |
| ` void`                                                                             | ` `[setCodec](https://developer.android.com/reference/android/net/rtp/AudioStream#setCodec(android.net.rtp.AudioCodec))`(`[AudioCodec](https://developer.android.com/reference/android/net/rtp/AudioCodec)` codec) ` Sets the[AudioCodec](https://developer.android.com/reference/android/net/rtp/AudioCodec). |
| ` void`                                                                             | ` `[setDtmfType](https://developer.android.com/reference/android/net/rtp/AudioStream#setDtmfType(int))`(int type) ` Sets the RTP payload type for dual-tone multi-frequency (DTMF) digits.                                                                                                                     |

| ### Inherited methods |
|-----------------------|---|
| From class` `[android.net.rtp.RtpStream](https://developer.android.com/reference/android/net/rtp/RtpStream)` ` |--------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` void`                                                                        | ` `[associate](https://developer.android.com/reference/android/net/rtp/RtpStream#associate(java.net.InetAddress,%20int))`(`[InetAddress](https://developer.android.com/reference/java/net/InetAddress)` address, int port) ` Associates with a remote host. | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/android/net/rtp/RtpStream#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                           | | ` `[InetAddress](https://developer.android.com/reference/java/net/InetAddress) | ` `[getLocalAddress](https://developer.android.com/reference/android/net/rtp/RtpStream#getLocalAddress())`() ` Returns the network address of the local host.                                                                                               | | ` int`                                                                         | ` `[getLocalPort](https://developer.android.com/reference/android/net/rtp/RtpStream#getLocalPort())`() ` Returns the network port of the local host.                                                                                                        | | ` int`                                                                         | ` `[getMode](https://developer.android.com/reference/android/net/rtp/RtpStream#getMode())`() ` Returns the current mode.                                                                                                                                    | | ` `[InetAddress](https://developer.android.com/reference/java/net/InetAddress) | ` `[getRemoteAddress](https://developer.android.com/reference/android/net/rtp/RtpStream#getRemoteAddress())`() ` Returns the network address of the remote host or`null`if the stream is not associated.                                                    | | ` int`                                                                         | ` `[getRemotePort](https://developer.android.com/reference/android/net/rtp/RtpStream#getRemotePort())`() ` Returns the network port of the remote host or`-1`if the stream is not associated.                                                               | | ` boolean`                                                                     | ` `[isBusy](https://developer.android.com/reference/android/net/rtp/RtpStream#isBusy())`() ` Returns`true`if the stream is busy.                                                                                                                            | | ` void`                                                                        | ` `[release](https://developer.android.com/reference/android/net/rtp/RtpStream#release())`() ` Releases allocated resources.                                                                                                                                | | ` void`                                                                        | ` `[setMode](https://developer.android.com/reference/android/net/rtp/RtpStream#setMode(int))`(int mode) ` Changes the current mode.                                                                                                                         | ||
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](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 `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](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`                                                                  | ` `[wait](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`                                                                  | ` `[wait](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*.                                                                                             | ||

## Public constructors

### AudioStream

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

```
public AudioStream (InetAddress address)
```

Creates an AudioStream on the given local address. Note that the local port is assigned automatically to conform with RFC 3550.

<br />

|                                     Parameters                                     ||
|-----------|-------------------------------------------------------------------------|
| `address` | `InetAddress`: The network address of the local host to bind to. <br /> |

|                                                                         Throws                                                                          ||
|-------------------------------------------------------------------------------------|--------------------------------------------------------------------|
| [SocketException](https://developer.android.com/reference/java/net/SocketException) | if the address cannot be bound or a problem occurs during binding. |

## Public methods

### getCodec

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

```
public AudioCodec getCodec ()
```

Returns the[AudioCodec](https://developer.android.com/reference/android/net/rtp/AudioCodec), or`null`if it is not set.

<br />

|                                         Returns                                          ||
|----------------------------------------------------------------------------------|--------|
| [AudioCodec](https://developer.android.com/reference/android/net/rtp/AudioCodec) | <br /> |

**See also:**

- [setCodec(AudioCodec)](https://developer.android.com/reference/android/net/rtp/AudioStream#setCodec(android.net.rtp.AudioCodec))  

### getDtmfType

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

```
public int getDtmfType ()
```

Returns the RTP payload type for dual-tone multi-frequency (DTMF) digits, or`-1`if it is not enabled.

<br />

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

**See also:**

- [setDtmfType(int)](https://developer.android.com/reference/android/net/rtp/AudioStream#setDtmfType(int))  

### getGroup

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

```
public AudioGroup getGroup ()
```

Returns the joined[AudioGroup](https://developer.android.com/reference/android/net/rtp/AudioGroup).

<br />

|                                         Returns                                          ||
|----------------------------------------------------------------------------------|--------|
| [AudioGroup](https://developer.android.com/reference/android/net/rtp/AudioGroup) | <br /> |

### isBusy

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

```
public final boolean isBusy ()
```

Returns`true`if the stream has already joined an[AudioGroup](https://developer.android.com/reference/android/net/rtp/AudioGroup).

<br />

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

### join

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

```
public void join (AudioGroup group)
```

Joins an[AudioGroup](https://developer.android.com/reference/android/net/rtp/AudioGroup). Each stream can join only one group at a time. The group can be changed by passing a different one or removed by calling this method with`null`.

<br />

|                               Parameters                               ||
|---------|---------------------------------------------------------------|
| `group` | `AudioGroup`: The AudioGroup to join or`null`to leave. <br /> |

|                                                                   Throws                                                                    ||
|--------------------------------------------------------------------------------------------------|-------------------------------------------|
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException) | if the stream is not properly configured. |

**See also:**

- [AudioGroup](https://developer.android.com/reference/android/net/rtp/AudioGroup)  

### setCodec

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

```
public void setCodec (AudioCodec codec)
```

Sets the[AudioCodec](https://developer.android.com/reference/android/net/rtp/AudioCodec).

<br />

|                        Parameters                        ||
|---------|-------------------------------------------------|
| `codec` | `AudioCodec`: The AudioCodec to be used. <br /> |

|                                                                Throws                                                                ||
|--------------------------------------------------------------------------------------------------------|------------------------------|
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | if its type is used by DTMF. |
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException)       | if the stream is busy.       |

### setDtmfType

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

```
public void setDtmfType (int type)
```

Sets the RTP payload type for dual-tone multi-frequency (DTMF) digits. The primary usage is to send digits to the remote gateway to perform certain tasks, such as second-stage dialing. According to RFC 2833, the RTP payload type for DTMF is assigned dynamically, so it must be in the range of 96 and 127. One can use`-1`to disable DTMF and free up the previous assigned type. This method cannot be called when the stream already joined an[AudioGroup](https://developer.android.com/reference/android/net/rtp/AudioGroup).

<br />

|                                 Parameters                                 ||
|--------|--------------------------------------------------------------------|
| `type` | `int`: The RTP payload type to be used or`-1`to disable it. <br /> |

|                                                                      Throws                                                                      ||
|--------------------------------------------------------------------------------------------------------|------------------------------------------|
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | if the type is invalid or used by codec. |
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException)       | if the stream is busy.                   |

**See also:**

- [AudioGroup.sendDtmf(int)](https://developer.android.com/reference/android/net/rtp/AudioGroup#sendDtmf(int))