Twigondrums
Twigondrums

Reputation: 13

Android playback recorded audio

I've been looking at this example https://stackoverflow.com/a/8974361/1191501 and it works perfectly. But my problem is how do I reference the recorded audio so it can be played back straight away?

the output code is:

recorder.setOutputFile("/sdcard/audio/"+filename);

and this definitely records the audio.

and then to playback the audio, I was using:

player.setDataSource();

but I don't know how to reference the filename bit so it plays back. Any ideas?

Upvotes: 0

Views: 901

Answers (2)

Swifty McSwifterton
Swifty McSwifterton

Reputation: 2667

I had similar problems playing audio from the SD card at one point. This is what did it for me:

private void playMedia() {
    String path = Environment.getExternalStorageDirectory() + "/audio_stuff.mp3";
    mediaPlayer = MediaPlayer.create(this, Uri.parse(path));
    mediaPlayer.start();
}

Make sure to release your MediaPlayer instance and set it to null when you are done. And just in case, make sure your SD card is not mounted when you try to play your audio file. :)

Upvotes: 1

blackbourna
blackbourna

Reputation: 1233

Looking here,

player.setDataSource("/sdcard/audio/"+filename);
player.prepare();
player.start();

would work I would think.

Upvotes: 0

Related Questions