Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to record mp3 radio (audio) stream

My favorite Radio station plays a radio audio stream in mp3 format. In my android application I can receive and play it without any problem.

How can I implement a recording function? I want to record the mp3 radio stream to my Android phones SD-Card.

I tried the MediaRecorder Class without any result...

Android Developer: MediaRecorder

...

mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);

...

Unfortunately I cannot choose something like:

mRecorder.setAudioSource(MediaRecorder.AudioSource.MP3_STREAM); ... ;-)

How can I record a mp3 radio stream? Thanks for any help or code snippets...

like image 593
user4500 Avatar asked Mar 21 '11 18:03

user4500


People also ask

How do I record streaming audio on Android?

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.


1 Answers

Perfect! Reading the audio stream "byte by byte" is the solution. Thank you!!

Here my code snippets:

        URL url = new URL("http://myradio,com/stream.mp3");
        inputStream = url.openStream();
        Log.d(LOG_TAG, "url.openStream()");

        fileOutputStream = new FileOutputStream(outputSource);
        Log.d(LOG_TAG, "FileOutputStream: " + outputSource);

        int c;

        while ((c = inputStream.read()) != -1) {
            Log.d(LOG_TAG, "bytesRead=" + bytesRead);
            fileOutputStream.write(c);
            bytesRead++;
        }
like image 51
user4500 Avatar answered Oct 19 '22 23:10

user4500