×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Jan 2010
    Posts
    52

    Problem with playing mp3 files

    Hey guys,

    I am developing a J2ME MIDlet for a S40 device (Nokia 6212).
    My MIDlet needs to play a mp3 file every once in a while. This is my code that plays the file from the resource:

    protected Player m_player = null;

    public void playMP3Sound(String file_name) {
    if (null != m_player) {
    m_player.deallocate();
    }
    try {
    InputStream in = getClass().getResourceAsStream(file_name);
    m_player = Manager.createPlayer(in,"audio/mpeg");}
    catch(Exception e) {
    return;
    }
    try
    {
    m_player.prefetch();
    m_player.start();
    }
    catch(Exception e){
    }
    }

    This code works. The problem is that after around 40 files (they are all around 10-20 KB in size and around 1-2 seconds in duration) are being played, the application throws
    an OutOfMemory exception and exits. Can someone see anything wrong with my code? Anything that needs
    deallocation?

    Thanks a lot!

  2. #2
    Registered User
    Join Date
    Aug 2009
    Posts
    15

    Re: Problem with playing mp3 files

    Hello, try this code:



    try to close the player, set up null and call System.gc().
    if (null != m_player) {
    m_player.close();
    m_player = null;
    System.gc(); //can help to free memory
    }
    Last edited by edprado; 2010-03-13 at 12:58.

  3. #3
    Regular Contributor
    Join Date
    Jan 2010
    Posts
    52

    Re: Problem with playing mp3 files

    Hey,

    Thanks again for your help.
    The following:
    String result = System.getProperty("audio.encodings"); //return all audio supported by device
    return audio/amr.
    I'm trying to convert my mp3 files to AMR. I tried using several converters and the files lose volume in the process (you can barely hear the sound). What is a good mp3 to amr conversion program?
    When I create the player, which encoding should I use (to replace the audio/mpeg)? is it audio/amr?

    Thanks again.
    Last edited by giaviv; 2010-03-13 at 13:42.

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    32

    Re: Problem with playing mp3 files

    Hi,

    When you are converting the Mp3 files to AMR you will surely gona loose on the sound quality and voice. This is the only reason due to which AMR files are much lighter the MP3. But you can try "switch mp3 converter"

    Regards,
    Aditya

Similar Threads

  1. SymPlayer – Wirelessly Play MP3 files directly from computer
    By hedge777 in forum News and Announcements
    Replies: 0
    Last Post: 2010-01-25, 02:27
  2. Problem playing wav files
    By vladgets in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2009-07-10, 12:42
  3. Modules required :)
    By neil.young in forum Symbian
    Replies: 20
    Last Post: 2009-06-07, 11:35
  4. Problem in playing in an audio file.
    By PankajNeve in forum Symbian
    Replies: 3
    Last Post: 2007-03-09, 13:52

Posting Permissions

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