Added in API level 29
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_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: