0
How do I run the sound in the Assets folder in Android Studio? When the sound is in the raw folder runs normal, but I need to run in the Assets folder, to pass the name dynamically, below is the example, but it still doesn’t 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();
}
}
Please avoid long discussions in the comments; your talk was moved to the chat
– Maniero