Using MediaPlayer or SoundPool

So for like the last couple hours I have been trying to figure out how to play an mp3 file in my app. Everything I have tried looking up has like a hundred lines of code and I don’t even know what it is doing. I have never tried using outside libraries before in processing so I think this could be causing some confusion for me too.
The best that I’ve found that would maybe work is this:

MediaPlayer mp = new MediaPlayer();
mp.setDataSource("/mnt/sdcard/yourdirectory/youraudiofile.mp3");
mp.prepare();
mp.start();

which I found here.

But from this, I don’t know what the file path would be to the mp3 file in the data folder.

1 Like

There are a couple of strategies as far as I understand, which I presented in a previous post of yours: Tracking high score for android

If you place your mp3 file in the data folder, you should be able to do this:

mp.setDataSource(dataPath("youraudiofile.mp3"));

You can also use the assets manager. Or explore examples working with external storage options.

Here I have an example playing sound tested on Android: A sound play exemplar please?

Notice that there might be some changes in Android Mode version 4.0.2 that Andres have implemented, as discussed [here])(https://github.com/processing/processing-android/issues/450#issuecomment-398517160).

Kf

1 Like