Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 660
longi Avatar asked Sep 27 '18 18:09

longi


1 Answers

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:

  • The app must have the RECORD_AUDIO permission.
  • The app must bring up the prompt displayed by MediaProjectionManager.createScreenCaptureIntent(), and the user must approve it.
  • The capturing and playing apps must be in the same user profile.

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

like image 72
Puka Avatar answered Oct 06 '22 23:10

Puka