How to record internal audio on Android devices or record MediaPlayer Audio Stream?
Asked Answered
P

1

13

I'm currently trying to record an audio stream which is played in MediaPlayer.

Actually I found some blog-post, saying it's not possible because of security / copyright reasons, but I couldn't find any official statements from Android/Google docs. Furthermore, there are screen capture apps like Mobizen which can record internal audio (at least Samsung devices seems to work).

So can someone tell, if

  1. internal audio is officially not allowed / supported?
  2. it's possible to record a stream with AudioRecorder which is played in MediaPlayer?

I'm not so sure if I'm entering the dark side at the moment?

What I already tried to answer the 2nd question:

  • recorded different MediaRecorder.AudioSource, but all record the microphone
  • found byte by byte for recording, but this is not working with MediaPlayer
Pufahl answered 27/9, 2018 at 18:55 Comment(2)
It's true that Mobizen seems to do that but maybe they are using screencasting API to that?Thach
I don't think that the official Android APIs allow what you want. Even Mobizen acknowledges this. My best guess is that Mobizen is probably using extra APIs that only Samsung and LG phones support (but if so, I haven't seen any public documentation of such APIs). This older post also discusses the problem: #17676642Cohleen
L
15

Coming with the new Android 10 API, there finally is an AudioPlaybackCapture API.

This API gives apps the ability to copy the audio being played by other apps. This feature is the analogue of screen capture, but for audio.

I personally haven't tested it, yet, but here are the required steps to capture audio, based on the dev guide.

Permissions needed to capture audio:

To capture the audio, you then need to build an AudioRecord object and add the AudioPlaybackCaptureConfiguration to it:

  1. Call AudioPlaybackCaptureConfiguration.Builder.build() to build an AudioPlaybackCaptureConfiguration.
  2. Pass the configuration to the AudioRecord by calling setAudioPlaybackCaptureConfig.

You can also constrain the capture by AUDIO_USAGE or a UID, see: Constraining capture by audio content

I highly recommend that you check out the Android Dev Guide.

Limitations

09/01/2020 Update: Android 10.0 now accounts for 29.04% of the Android market share, according to StatCounter.

Mobile & Tablet Android Version Market Share Worldwide

Mobile & Tablet Android Version Market Share Worldwide, from July 2019 to July 2020. Source: StatCounter


Old answer: Very few devices are running on Android, 10. Google has not released yet the market share, but we can guess that it is at most less than 10%, which is the market share of Android 9.0.

Data collected during a 7-day period ending on May 7, 2019. Any versions with less than 0.1% distribution are not shown.

Data collected during a 7-day period ending on May 7, 2019. Any versions with less than 0.1% distribution are not shown. Source: Distribution dashboard

Lymph answered 5/2, 2020 at 14:36 Comment(1)
can you please help me in this #64197148Kagoshima

© 2022 - 2024 — McMap. All rights reserved.