AudioGroup
open classAudioGroup
kotlin.Any | |
↳ | android.net.rtp.AudioGroup |
An AudioGroup is an audio hub for the speaker, the microphone, and AudioStream
s. 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 |
static Int |
This mode is similar to |
static Int |
This mode indicates that the speaker, the microphone, and all |
static Int |
This mode is similar to |
Public constructors | |
---|---|
Creates an empty AudioGroup. |
|
AudioGroup(context: Context) Creates an empty AudioGroup. |
Public methods | |
---|---|
open Unit |
clear() Removes every |
open Int |
getMode() Returns the current mode. |
open Array<AudioStream!>! |
Returns the |
open Unit |
Sends a DTMF digit to every |
open Unit |
Changes the current mode. |
Protected methods | |
---|---|
open Unit |
finalize() |
Constants
MODE_ECHO_SUPPRESSION
static valMODE_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
static valMODE_MUTED: Int
Deprecated: Deprecated in Java.
This mode is similar to MODE_NORMAL
except the microphone is disabled.
Value: 1
MODE_NORMAL
static valMODE_NORMAL: Int
Deprecated: Deprecated in Java.
This mode indicates that the speaker, the microphone, and all 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.
Value: 2
MODE_ON_HOLD
static valMODE_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
AudioGroup()
Deprecated: Replaced by AudioGroup(android.content.Context)
Creates an empty AudioGroup.
AudioGroup
AudioGroup(context: Context)
Creates an empty AudioGroup.
Parameters | |
---|---|
context |
Context: Context the group belongs to This value cannot be null . |
Public methods
clear
open funclear(): Unit
Deprecated: Deprecated in Java.
Removes every AudioStream
in this group.
getMode
open fungetMode(): Int
Deprecated: Deprecated in Java.
Returns the current mode.
getStreams
open fungetStreams(): Array<AudioStream!>!
Deprecated: Deprecated in Java.
Returns the AudioStream
s in this group.
sendDtmf
open funsendDtmf(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
open funsetMode(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
protected open funfinalize(): Unit
Deprecated: Deprecated in Java.
Exceptions | |
---|---|
java.lang.Throwable |
the Exception raised by this method |