Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Nov 2009

    Angry Sound playing consuming memory - J2ME, S40, 6212

    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?

  2. #2
    Registered User
    Join Date
    Nov 2009

    Re: Sound playing consuming memory - J2ME, S40, 6212

    To answer my own question - in case others face it.

    The examples I have found are over simplistic, this page helped: http://jcs.mobile-utopia.com/jcs/24237_Player.html

    and it seems that if a previous player exists, then creating a new one before calling
    player.close() and
    causes problems.

    To be on the safe side, I ended up with this elaborate method:

    public void positive() {
    try {
    if ( p != null ){

    InputStream is = getClass().getResourceAsStream("apert.wav");
    try {
    p = Manager.createPlayer( is, "audio/x-wav" );
    } catch ( MediaException pe ) {
    p = Manager.createPlayer( is, "audio/wav" );
    catch ( Exception ex )

    Where I keep track of previous players, and stop and deallocate them before creating a new one.

    This makes it robust (500 calls tested so far).

    But audio playback stops quite soon after I start, making it a bit of a hollow victory.
    I suspected that was caused one sound being a bit longer than the others and being stopped, but not sure.
    So, I shortened the sounds and put a Thread.sleep() between each of duration longer than the sound, but no improvment.

    Another page I read on the net said that on all Nokia devices, I should NEVER call de-allocate us that "really messes things up"

    Any recipe from the developers at Nokia for getting reliable .wav sound playback on a 6212???

    Last edited by andrew_d_mackenzie; 2010-04-12 at 23:05. Reason: aditional information after further testing

  3. #3
    Registered User
    Join Date
    Sep 2010

    Re: Sound playing consuming memory - J2ME, S40, 6212

    Hey There,

    Surely you probably read this known issue.

    This Code seems to do the trick for me.

    midiPlayer = Manager.createPlayer(getClass().getResourceAsStream(fname), "audio/midi");
    Thread.currentThread().sleep(midiPlayer.getDuration() / 1000 );
    midiPlayer = null;

    close the player before setting it to null. Loops for hours!
    Last edited by circuitmaster; 2010-09-26 at 20:18.

Similar Threads

  1. playing sound in j2me
    By jiten_shah18 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2010-03-13, 15:06
  2. N97 not playing sound in J2ME application
    By t.kumar in forum Mobile Java General
    Replies: 3
    Last Post: 2010-02-26, 13:08
  3. J2ME video streaming memory issues
    By sreyansjain in forum Mobile Java Media (Graphics & Sounds)
    Replies: 0
    Last Post: 2008-03-17, 06:36
  4. Problem on playing sound in emulator
    By mhahn0106 in forum Symbian Tools & SDKs
    Replies: 0
    Last Post: 2004-01-12, 06:00
  5. can not successfully link any sample using .NET
    By lobotomat in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2002-08-20, 00:29

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts