Comment puis-je intercepter le stream audio sur un appareil Android?

Supposons que nous ayons le scénario suivant: quelque chose est en train de jouer sur un appareil Android (un mp3 par exemple, mais il pourrait s’agir de tout ce qui utilise la partie audio d’un appareil Android). À partir d’une application (application Android :)), je voudrais intercepter le stream audio pour l’parsingr, l’enregistrer, etc. Depuis cette application (disons “l’parsingur”), je ne souhaite pas lancer de fichier MP3 ou autre. Tout ce que je veux, c’est d’avoir access au stream audio d’android.

Tout conseil est apprécié, il pourrait s’agir d’une solution Java ou C ++.

http://developer.android.com/reference/android/media/MediaRecorder.html

public class AudioRecorder { final MediaRecorder recorder = new MediaRecorder(); final Ssortingng path; /** * Creates a new audio recording at the given path (relative to root of SD * card). */ public AudioRecorder(Ssortingng path) { this.path = sanitizePath(path); } private Ssortingng sanitizePath(Ssortingng path) { if (!path.startsWith("/")) { path = "/" + path; } if (!path.contains(".")) { path += ".3gp"; } return Environment.getExternalStorageDirectory().getAbsolutePath() + path; } /** * Starts a new recording. */ public void start() throws IOException { Ssortingng state = android.os.Environment.getExternalStorageState(); if (!state.equals(android.os.Environment.MEDIA_MOUNTED)) { throw new IOException("SD Card is not mounted. It is " + state + "."); } // make sure the directory we plan to store the recording in exists File directory = new File(path).getParentFile(); if (!directory.exists() && !directory.mkdirs()) { throw new IOException("Path to file could not be created."); } recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setOutputFile(path); recorder.prepare(); recorder.start(); } /** * Stops a recording that has been previously started. */ public void stop() throws IOException { recorder.stop(); recorder.release(); } }