Issue
I have a few raw music files that I'd like for a single MediaPlayer to play. After many attempts I was able to get the MediaPlayer to switch between songs. However, one of my raw files keeps returning a FileNotFoundException. This is bizzare to me because I imported it into my raw folder just like all of the other files that work. I also am accessing it in the exact same way as the other files.
Here's the code where I'm accessing the file (It's called victory_music):
AssetFileDescriptor afd = CPU.rawToFile(Results.this, R.raw.victory_music);
And here's the code where I'm accessing the other files (where it actually works):
AssetFileDescriptor afd = CPU.rawToFile(Results.this, R.raw.defeat_music);
And
mPlayer = MediaPlayer.create(MainMenu.this, R.raw.battle_music);
Here's the error I'm getting:
05-30 16:20:24.439: E/AndroidRuntime(3151): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my.app/com.my.app.MainMenu}: android.content.res.Resources$NotFoundException: File res/raw/you_win from drawable resource ID #0x7f040003
I've tried cleaning/building, deleting the file and re-importing it, and even using a completely different file and name, but it seems like whenever I add a new file now it doesn't work anymore.
Any help would be greatly appreciated!
Solution
Eureka! I knew that I had made some sort of silly mistake!
The files that I had in raw were not named correctly. They should be named "title.mp3" but instead I had just named them "title" since when accessing you truncate the file type at the end such as:
R.raw.title
This must have confused me and I ended up truncating my names in my raw directory.
I'm still a little unsure about why my wrong naming convention still worked for files over 1MB, however.
Answered By - Ivan Kelber
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.