Extract Audio from Mp4 and Save to Sd Card (MediaExtractor)
<p>I have a mp4 video file in my sd card. I would like to extract the audio from the video and then save the extracted audio as a separate file on the sd card using MediaExtractor Api. Here is the code I've tried:</p>

<pre><code>  MediaExtractor extractor = new MediaExtractor();
  extractor.setDataSource(MEDIA_PATH_To_File_On_SDCARD);
  for (i = 0; i &lt; extractor.getTrackCount(); i++) {
            MediaFormat format = extractor.getTrackFormat(i);
            String mime = format.getString(MediaFormat.KEY_MIME);
            if (mime.startsWith("audio/")) {
                extractor.selectTrack(i);
                decoder = MediaCodec.createDecoderByType(mime);

                if(decoder != null)
                {
                   decoder.configure(format, null, null, 0);
                }

                break;
            }
        }
</code></pre>

<p>Am stuck here I have no idea of how to take the selected audio track and save it to the sd card.</p>