I'm new in android development trying to play a simple audio file. I organized my audio files in multiple nested folders.
Here is the complete source on disk "app/src/main/res/raw/sounds/first/nested/my_sound_1.mp3" ... Certainly there are other files in different folders.
This is the method I'm using to play the audio file
fun audioPlayer(path : String, fileName: String) {
var mediaPlayer = MediaPlayer()
try {
mediaPlayer.setDataSource(path + File.separator + fileName)
mediaPlayer.prepare()
mediaPlayer.start()
} catch (e: Exception) {
e.printStackTrace()
}
}
and on a button click event I'm using this code
audioPlayer("raw.sounds.first.nested", "my_sound_1.mp3")
Here is the error.
java.io.IOException: setDataSource failed.