The problem I'm trying to solve is the activity that should play audio files. Most files will be created by the user (and saved in external storage) and therefore will be played with the following code (based on the Google example code):
MediaPlayer mPlayer = new MediaPlayer();
mPlayer.setDataSource(filename);
mPlayer.prepare();
mPlayer.start();
Some audio files, however, will be included in the application, usually played with the following code:
MediaPlayer mPlayer = MediaPlayer.create(getBaseContext(), R.raw.filename);
mPlayer.prepare();
mPlayer.start();
The problem is that I would like to be able to play audio files in the source folder in the same way as I play user-created files, since I do not necessarily know what will be needed. I tried to get the URI of the audio file in the source folder and play it with the following code:
Uri uri = Uri.parse("android/resource://com.my.package/" + R.raw.filename);
MediaPlayer mPlayer = new MediaPlayer();
mPlayer.setDataSource(uri.toString());
mPlayer.prepare();
mPlayer.start();
But nothing happens. No error messages, no sound.
, , , . .