I'm trying to play (reliably) sound from .wav files in a 6212 classic (S40).
I followed the instructions in this Wiki article:
How to Play sound in Java ME
InputStream is = getClass().getResourceAsStream("sound.wav");
Player p = Manager.createPlayer(is, "audio/X-wav");
But when I used this in a MIDlet I ran into problems. I'm playing a short WAV format "dong" sound that is less than a second long.
After playing a few sounds it stops playing (i.e. don't make any noise).
If the MIDlet continues to try, it fails with an out of memory error.
After much trial and error I wrote a test MIDlet that plays sounds using that method with a 500ms delay between each.
In the emulator it stops playing sounds after about 5 or 6, then runs out of memory and crashes with an exception in about 28 sounds played.
Doesn't really change with the delay is increased to 1sec or 2sec.
In the real device (6212) it stops playing sounds after about 10 times, then crashes with out of memory after about 28.
Are their any special instructions that need to be followed when using that method?
Any alternative methods that don't consume memory like this?