Some months ago, with Android ICS (4.0), I developed an android kernel module which intercepted the "pcmC0D0p"-module to fetch all system audio.
My target is to stream ALL audio (or at least the played music) to a remote speaker via AirPlay.
The kernel module worked, but there where several problems (kernel-versions, root-privileges etc.) so I stopped working on this.
Now, we have Android 4.1 and 4.2 and I have new hope!
Who has an idea how to capture the audio in Android?
I had following ideas:
Connect via bluetooth to the same phone, set routing to BT and grab the audio on the "other end": this shouldn't work
Intercept the audio with a kernel module like done before: hardcore, get it worked but not applicable
JACK Audio Connection Kit: sadly Android uses "tinyALSA" and not "ALSA". TinyALSA does NOT support any filters like JACK (but this brought the idea with the kernel module)
Use PulseAudio as a replacement for AudioFlinger, but this is also not applicable
EDIT (forgot them):
I compiled "tinymix" (baby-version of ALSA-mixer) from tinyALSA (the ALSA on Android) and tried to route the audio-out to mic-in - but with no success (not understandable for me). And this also needs rooting: not applicable
I tested OpenSL ES, but I'm not a C-crack and it ended in "I can record microphone, but no more" (maybe I was wrong?)
I just found ROUTE_TYPE_LIVE_AUDIO:
A device that supports live audio routing will allow the media audio stream to be routed to supported destinations. This can include internal speakers or audio jacks on the device itself, A2DP devices, and more.
Once initiated this routing is transparent to the application. All audio played on the media stream will be routed to the selected destination.
Maybe this helps in any way?
I'm running out of ideas but want to "crack this nut", maybe someone can help me?
EDIT:
I'm really new in C & kernel-coding (but I successfully created a cross-compiled audio-interception-module) - but isn't it in any way possible to listen at the point the PCM-data goes from userspace (JAVA, C-layer?) to the kernel-space (tinyALSA, kernel-module), without hacking & rooting?
Swipe down from the top of your screen to see the quick settings tiles and tap the screen recorder button. A floating bubble will appear with a record and microphone button. If the latter is crossed out, you're recording internal audio, and if it's not, you get sound straight from your phone's mic.
Go to Audio source and select Internal audio. You can use a third-party screen recorder app from the Google Play Store if your phone doesn't have one built-in. Using the AZ Screen Recorder as an example, go to the app settings, enable Record audio, tap on Audio source, and select Internal audio.
Since Android 7.0 Nougat, Google disabled the ability for apps to record your internal audio, which means there's no base level method to record the sounds from your apps and games as you record the screen.
ADV Screen Recorder is another Android screen recorder with internal audio. With this app, you can easily capture the sound coming from your smartphone without requiring root. Moreover, this internal audio app lets you record screen, system sound, microphone, or both at the same time with high quality.
You must pass audio traffic through your local socket server:
Create local socket server
Modify audio http stream address to path is thru your local socket server, for example for address
http://example.com/stream.mp3 -> http://127.0.0.1:8888/http://example.com/stream.mp3
where 8888 is your socket port.
Play
http://127.0.0.1:8888/http://example.com/stream.mp3
with default media player
Read all incoming requests to port 8888 in your local socket server, analyze it and pass to example.com server.
Read response from example.com and pass it to local client (media player). HERE you can capture audio stream!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With