Open darwusch opened 2 years ago
Hi julioz:
I use MediaPlayer in my app and play a streaming song url.
I encounter all values are zero of capturedAudioSamples array
event though I use real device.
But, I can record audio when I use Youtube App that play audio.
Do you know what happen?
Hi julioz: I use MediaPlayer in my app and play a streaming song url. I encounter all values are zero of
capturedAudioSamples array
event though I use real device.But, I can record audio when I use Youtube App that play audio.
Do you know what happen?
Somewhere I read that capturing audio only works on playing apps that are written with minimalSDK 29. Might be that this is one of the reasons.
I found the infomation in Android Developer Document: Pass an AUDIO_USAGE to AudioPlaybackCaptureConfiguration.addMatchingUsage() to permit capturing a specific usage. Call the method multiple times to specify more than one usage.
I try to set the AudioPlaybackCaptureConfiguration
.
I set two MatchingUsage with AudioAttributes.USAGE_MEDIA
and AudioAttributes.USAGE_UNKNOWN
.
val config = AudioPlaybackCaptureConfiguration.Builder(mediaProjection!!) .addMatchingUsage(AudioAttributes.USAGE_MEDIA) .addMatchingUsage(AudioAttributes.USAGE_UNKNOWN) .build()
So that I can record both of my app audio from MediaPlayer and Youtube App audio.
Any idea what config will I have to use to capture audio from chrome browser app
?
When I run this code in the emulator when playing music with another app, nothing is recorded. I tried several music apps. All permissions are given. I do get the popup message about the recording and I see the icon on top about the recoding. The recoding file is saved, but when I open it, it only contains zeros. I tried it on android 10 and 11. Android 10: Automotive emulator and Polestar 2 Android 11: Automotive emulator (both with headset on and off)