Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid > 4.0 : Ideas how to record/capture internal audio (e.g. STREAM_MUSIC)?
    primarykey
    data
    text
    <p>Some months ago, with Android ICS (4.0), I developed an android kernel module which intercepted the "pcmC0D0p"-module to fetch all system audio.</p> <p>My target is to stream ALL audio (or at least the played music) to a remote speaker via AirPlay.</p> <p>The kernel module worked, but there where several problems (kernel-versions, root-privileges etc.) so I stopped working on this.</p> <p>Now, we have Android 4.1 and 4.2 and I have new hope!</p> <p>Who has an idea how to capture the audio in Android?</p> <p>I had following ideas:</p> <ol> <li><p><a href="https://stackoverflow.com/questions/13875126/android-possible-to-connect-bluetooth-to-self/13879176#13879176">Connect via bluetooth</a> to the same phone, set routing to BT and grab the audio on the "other end": this shouldn't work</p></li> <li><p>Intercept the audio with a kernel module like done before: hardcore, get it worked but not applicable</p></li> <li><p><a href="http://jackaudio.org/" rel="nofollow noreferrer">JACK Audio Connection Kit</a>: sadly Android uses "tinyALSA" and not "ALSA". TinyALSA does NOT support any filters like JACK (but this brought the idea with the kernel module)</p></li> <li><p>Use PulseAudio as a replacement for AudioFlinger, but this is also not applicable</p></li> </ol> <hr> <p>EDIT (forgot them):</p> <ol start="5"> <li><p>I compiled "tinymix" (baby-version of ALSA-mixer) from <a href="https://github.com/tinyalsa/tinyalsa" rel="nofollow noreferrer">tinyALSA</a> (the ALSA on Android) and tried to route the audio-out to mic-in - but with no success (<a href="https://stackoverflow.com/questions/10733214/android-how-to-configure-tinymix-to-record-system-audio-with-tinycap">not understandable for me</a>). And this also needs rooting: not applicable</p></li> <li><p>I tested <a href="http://www.khronos.org/opensles/" rel="nofollow noreferrer">OpenSL ES</a>, but I'm not a C-crack and it ended in "I can record microphone, but no more" (maybe I was wrong?)</p></li> </ol> <hr> <p>I just found <a href="http://developer.android.com/reference/android/media/MediaRouter.html#ROUTE_TYPE_LIVE_AUDIO" rel="nofollow noreferrer">ROUTE_TYPE_LIVE_AUDIO</a>:</p> <blockquote> <p>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.</p> <p>Once initiated this routing is transparent to the application. All audio played on the media stream will be routed to the selected destination.</p> </blockquote> <p>Maybe this helps in any way?</p> <p>I'm running out of ideas but want to "crack this nut", maybe someone can help me?</p> <p>EDIT:</p> <p>I'm really new in C &amp; 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 &amp; rooting?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. COThere's no support in Android for doing this, so it would only work on a custom ROM where you've added this functionality (e.g. by modifying some kernel module as you suggested). Newer Qualcomm platforms support WiFi Display though, which is a different technology from AirPlay that serves as a kind of wireless HDMI connection to compatible devices (e.g. some newer TVs). IIRC, the MediaRouter is a widget that you can add to your app and allows the user to select where audio should be routed. It only allows the user to select devices supported/detected by the phone/tablet though.
      singulars
    2. COThank you for your response. That's really bad :*( But I'll keep on searching for a solution. I will extend my "test"-documentation above, forgot something.
      singulars
    3. CO"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?" Unfortunately for you there isn't. Another thing you might want to keep in mind is all playback doesn't necessarily go to the same ALSA playback device (pcmCxDyp). Normal playback might go to one device, low power playback to another, and low latency playback to yet another. amixer/tinymix won't do any good unless the platform provides some sort of readback of played data, which typically isn't the case.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload