AudioPlaybackCaptureConfiguration
public
final
class
AudioPlaybackCaptureConfiguration
extends Object
java.lang.Object | |
↳ | android.media.AudioPlaybackCaptureConfiguration |
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_UNKNOWN
orAudioAttributes#USAGE_GAME
orAudioAttributes#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
targetSdkVersion
MUST 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 | |
---|---|
Public methods
getExcludeUids
public int[] getExcludeUids ()
Returns | |
---|---|
int[] |
the UIDs passed to Builder#excludeUid(int) .
This value cannot be null . |
getExcludeUsages
public int[] getExcludeUsages ()
getMatchingUids
public int[] getMatchingUids ()
Returns | |
---|---|
int[] |
the UIDs passed to Builder#addMatchingUid(int) .
This value cannot be null . |
getMatchingUsages
public int[] getMatchingUsages ()
getMediaProjection
public MediaProjection getMediaProjection ()
Returns | |
---|---|
MediaProjection |
the MediaProjection used to build this object.
This value cannot be null . |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-04-11 UTC.