Im puttin the file "hello.mp3" in the assets-folder, and Im using the following code:
- Code: Select all
String soundUrl = "file:///android_asset/hello.mp3";
mp = new MediaPlayer();
try {
mp.setDataSource(soundUrl);
mp.prepare();
mp.start();
}
catch (IOException e) {}
catch (IllegalArgumentException e) {}
catch (IllegalStateException e) {}
This code works when I put the "hello.mp3" in the res/raw-folder:
- Code: Select all
mp = new MediaPlayer();
mp = MediaPlayer.create(getBaseContext(), R.raw.hello);
mp.start();
Problem with the last code is that I need to load the sound-files dynamically, and apparently you cant create a string or a uri with the correct sound-file at the end and insert that as the second parameter in the MP.create()-function.
Pseudocode - NOT WORKING
- Code: Select all
String mySound = "hello";
Uri myUri = "R.raw." + mySound;
...
mp = MediaPlayer.create(getBaseContext(), myUri);
Any ideas?



