public
final
class
AudioPlaybackCaptureConfiguration
extends Object
Configuration for capturing audio played by other apps. When capturing audio signals played by other apps (and yours), you will only capture a mix of the audio signals played by players (such as AudioTrack or MediaPlayer) which present the following characteristics:
- the usage value MUST be
AudioAttributes.USAGE_UNKNOWNorAudioAttributes.USAGE_GAMEorAudioAttributes.USAGE_MEDIA. All other usages CAN NOT be captured. - AND the capture policy set by their app (with
AudioManager.setAllowedCapturePolicy) or on each player (withAudioAttributes.Builder.setAllowedCapturePolicy) isAudioAttributes.ALLOW_CAPTURE_BY_ALL, whichever is the most strict. - AND their app attribute allowAudioPlaybackCapture in their manifest
MUST either be:
- set to "true"
- not set, and their
targetSdkVersionMUST be equal to or greater thanBuild.VERSION_CODES.Q. Ie. Apps that do not target at least Android Q must explicitly opt-in to be captured by a MediaProjection.
- AND their apps MUST be in the same user profile as your app (eg work profile cannot capture user profile apps and vice-versa).
An example for creating a capture configuration for capturing all media playback:
MediaProjection mediaProjection;
// Retrieve a audio capable projection from the MediaProjectionManager
AudioPlaybackCaptureConfiguration config =
new AudioPlaybackCaptureConfiguration.Builder(mediaProjection)
.addMatchingUsage(AudioAttributes.USAGE_MEDIA)
.build();
AudioRecord record = new AudioRecord.Builder()
.setAudioPlaybackCaptureConfig(config)
.build();
See also:
Summary
Nested classes | |
|---|---|
class |
AudioPlaybackCaptureConfiguration.Builder
Builder for creating |
Public methods | |
|---|---|
int[]
|
getExcludeUids()
|
int[]
|
getExcludeUsages()
|
int[]
|
getMatchingUids()
|
int[]
|
getMatchingUsages()
|
MediaProjection
|
getMediaProjection()
|
Inherited methods | |||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
From class
| |||||||||||||||||||||||
Public methods
getExcludeUids
Added in API level 29
public int[] getExcludeUids ()
| Returns | |
|---|---|
int[] |
the UIDs passed to Builder.excludeUid(int).
This value cannot be null. |
getExcludeUsages
Added in API level 29
public int[] getExcludeUsages ()
getMatchingUids
Added in API level 29
public int[] getMatchingUids ()
| Returns | |
|---|---|
int[] |
the UIDs passed to Builder.addMatchingUid(int).
This value cannot be null. |
getMatchingUsages
Added in API level 29
public int[] getMatchingUsages ()
getMediaProjection
Added in API level 29
public MediaProjection getMediaProjection ()
| Returns | |
|---|---|
MediaProjection |
the MediaProjection used to build this object.
This value cannot be null. |
See also: