简体   繁体   中英

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...

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++;
        }

Maybe you should read audio stream "byte by byte" and then place it into new file? Like a simple file copy operation, using inputstream-outputstream.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM