How do I play sound in the assets folder in Android Studio? When the sound is in the raw folder it performs normal, but I need to run in the assets folder, to pass the name dynamically, below is the example, but it still does not work.
public void playSom() {
try {
System.out.println("Iniciando Som...");
if (mp01.isPlaying()) {
mp01.stop();
mp01.release();
mp01 = new MediaPlayer();
}
AssetFileDescriptor assets = getAssets().openFd("errou_1.mp3");
mp01.setDataSource(assets.getFileDescriptor(), assets.getStartOffset(), assets.getLength());
//mp01.prepare();
mp01.prepareAsync();
mp01.setVolume(1f, 1f);
//mp01.setLooping(true);
mp01.start();
assets.close();
if (mp01.isPlaying()) {
System.out.println("Tocando Som ( OK )...");
}
} catch (Exception e) {
e.printStackTrace();
}
}