I am having a problem With SoundPool as it refuses to work with my .ogg files. I am getting this error:
AudioFlinger could not create track, status: -12
Error creating AudioTrack
I’ve found a thread concerning this and the (possible) answer is:
Make sure you use .ogg media files with constant bitrate!
Is this the case? If yes – which application to use (Audacity doesn’t support .ogg custom export settings). If not – what else could be wrong?
As a side note – before I used MediaPlayer but now I want to play a few sounds parallel.
MAJOR EDIT: FOUND A WAY TO FIX YOUR DAY!! SCROLL DOWN BELOW!!
I’m in the same boat with you. Before reading, I must let you know that I failed to provide an answer that can fix this problem.
I have seen many, many Stack Overflow topics regarding SoundPool, but I haven’t seen a lot of SoundPool problems with this in regard with Java code from an Android book:
Here’s the code snipped from Beginning Android 4 Game Development source code provided here (see below). You get the explosion.ogg file there (in the trunk, find the /asset folder of Chapter 4 – Android Basics). You have to click on “View raw file” on your right to obtain the file.
All I did was I copied the source code directly into Eclipse, and added the explosion.ogg file provided from the trunk, into my project. I executed Android emulator, tried playing the file, and I can tell you I still get the same Logcat errors quoted above.
A person provided a video on Youtube stating that SoundPool works normally. Video link is given below. I did what the video instructed me to code, I grabbed the same explosion.ogg file I got from the second link provided above. I still get these errors:
I do know that SoundPool exists since Android 1.0, at API level 1. There shouldn’t be any reason for SoundPool to fail to work, even when I have proof that SoundPool works (the video link, 2nd one).
These are my findings and may or may not help others in a good way. In short, you’re not alone here.
Source:
EDIT: I am able to play sounds from SoundPool.
Here’s my code:
What I did was refactor my code around. I learned this tip from one of the comments in the Youtube video link, where the author of the comment goes by the name of “ErichLancaster”. All credits go to him. I hoped this helped you out.
I also set the Android emulator resolution size to QVGA, if it really matters or not.