×

Discussion Board

Results 1 to 13 of 13
  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    28

    Development of mp3 player in J2ME

    Hi all,
    I am new in j2me development and desperate to know can i develop mp3 music player in J2ME?

    if anyone recommend me any document so i will be very thankful.

    Thanks
    Kami

  2. #2
    Regular Contributor
    Join Date
    Apr 2007
    Posts
    233

    Re: Development of mp3 player in J2ME

    You need jsr75 + jsr135, to search for and play mp3 files.

  3. #3
    Registered User
    Join Date
    Dec 2005
    Location
    Brazil
    Posts
    1,884

    Re: Development of mp3 player in J2ME

    Hi Kami,

    Yes, here are some good docs by Forum Nokia:

    JSR-75 - MIDP: FileConnection API Developer's Guide (with Example) v2.0
    http://www.forum.nokia.com/info/sw.n..._0_en.zip.html

    JSR-135 - MIDP: Mobile Media API Developer's Guide v2.1
    http://www.forum.nokia.com/info/sw.n..._1_en.pdf.html

    MIDP: Mobile Media API Example - Media Sampler
    http://www.forum.nokia.com/info/sw.n..._v1_0.zip.html

    MIDP: Mobile Media API Support In Nokia Devices
    http://www.forum.nokia.com/info/sw.n..._0_en.pdf.html

    Hope this helps
    Juarez Alvares Barbosa Junior - Brazil

  4. #4
    Registered User
    Join Date
    Jun 2007
    Posts
    28

    Re: Development of mp3 player in J2ME

    HI all,

    Actually i tried to run this code on wireless toolkit2.5 but i can compile this code quite easily but on runtime its giving exceptions:



    Please Can anybody help me out:

    Source code is: PlayerMidlet.java

    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;

    public class PlayerMidlet extends MIDlet implements CommandListener, ItemStateListener {

    Display display;
    Command exitCommand = new Command("Exit", Command.EXIT, 99);
    Command stopCommand = new Command("Stop", Command.ITEM, 1);
    Command startCommand = new Command("Start", Command.ITEM, 1);
    Command rewindCommand = new Command("Rewind", Command.ITEM, 2);
    Form form;
    Source source;
    Gauge gauge;
    int itemNum;

    public PlayerMidlet()
    {
    display = Display.getDisplay(this);

    form = new Form(" Secure Mobile Music Player ");
    form.addCommand(startCommand);
    form.addCommand(exitCommand);
    form.setCommandListener(this);


    gauge = new Gauge("Player Volume", true , 100 , 50);
    form.append(gauge);
    gauge.setLayout(0x800);
    itemNum = form.append(" Value: " + gauge.getValue());
    form.setItemStateListener(this);

    source = new Source("/res/sound.WAV ");
    }

    protected void startApp() throws MIDletStateChangeException
    {
    display.setCurrent(form);
    }

    protected void pauseApp()
    {
    source.stop();
    }

    protected void destroyApp(boolean unconditional)
    throws MIDletStateChangeException
    {
    source.destroy();
    }

    public void itemStateChanged(Item item)
    {
    if (item == gauge )
    {
    source.setLevel(gauge.getValue());
    form.delete(itemNum);
    form.append("Value: " + gauge.getValue());
    }
    }

    public void commandAction( Command c, Displayable s)
    {

    if( c == stopCommand )
    {
    source.stop();
    form.removeCommand(stopCommand);
    form.addCommand(startCommand);
    form.addCommand(rewindCommand);
    }
    else if ( c == startCommand )
    {
    source.start();
    form.removeCommand(startCommand);
    form.removeCommand(rewindCommand);
    form.addCommand(stopCommand);
    }
    else if ( c == rewindCommand )
    {
    source.rewind();
    form.removeCommand(rewindCommand);

    }
    else if ( c == exitCommand )
    {
    try
    {
    destroyApp(false);
    notifyDestroyed();
    }
    catch (MIDletStateChangeException e)
    {
    }
    }
    }
    }


    _________________________________

    Source code: Source.java


    import javax.microedition.media.*;
    import javax.microedition.media.control.*;
    import java.io.*;

    public class Source implements PlayerListener
    {
    Player p;
    VolumeControl volC;

    Source(String fileName)
    {
    InputStream is = getClass().getResourceAsStream(fileName);

    if(is == null )
    {
    System.out.println("Error creating inputstream" + fileName);
    }

    try
    {
    p = Manager.createPlayer(is, "audio/X-wav");

    if(p == null )
    {
    System.out.println("Error creating player" + fileName);
    }
    else
    {
    p.addPlayerListener(this);
    p.realize();
    p.prefetch();
    p.setLoopCount(-1);
    System.out.println("Realized Player: "+ fileName);
    }
    }
    catch (IOException e)
    {
    System.out.println(e);
    }
    catch (MediaException e)
    {
    System.out.println(e);
    }

    volC = (VolumeControl)p.getControl("VolumeControl");
    }

    public void destroy()
    {
    if (p != null)
    {
    p.close();
    }
    }

    public void start()
    {
    if (p != null)
    {
    try
    {
    p.start();
    }
    catch(MediaException e)
    {
    System.out.println(e);
    }
    }

    }

    public void stop()
    {
    if (p != null && p.getState() == Player.STARTED)
    {
    try
    {
    p.stop();
    }
    catch(MediaException e)
    {
    System.out.println(e);
    }
    }

    }

    public void rewind()
    {
    if (p != null && p.getState() == Player.PREFETCHED)
    {
    try
    {
    p.setMediaTime(-1);
    }
    catch(MediaException e)
    {
    System.out.println(e);
    }
    }

    }

    public int setLevel(int level)
    {
    return volC.setLevel(level);
    }

    public void playerUpdate(Player p,String event,Object eventData)
    {
    if(event == STARTED)
    System.out.println("Player Stated");
    else if ( event == STOPPED)
    System.out.println("Player Stopped");
    else if ( event == END_OF_MEDIA)
    System.out.println("Player AT END OF FILE");
    else if ( event == VOLUME_CHANGED)
    System.out.println("Player VOULUME CHANGED");
    else if ( event == CLOSED)
    System.out.println("Player CLOSED");
    }
    }

    ______________________________

    Thanks in Advance:
    Kami

  5. #5
    Registered User
    Join Date
    Dec 2005
    Location
    Brazil
    Posts
    1,884

    Re: Development of mp3 player in J2ME

    Hi,

    "but i can compile this code quite easily but on runtime its giving exceptions:"
    Which ones?
    Juarez Alvares Barbosa Junior - Brazil

  6. #6
    Registered User
    Join Date
    Jun 2007
    Posts
    28

    Re: Development of mp3 player in J2ME

    hi,

    i am sorry actually i just start learning J2ME ,well may be now you can undersatnd what i mean......


    I put two java files.
    first one: playerMidlet.java
    second one : Source.java

    Actually you see in PlayerMidlet.java i am using Source.java, so i just need to compile PlayerMidlet.java, and when i compile PlayerMidlet.java so there is no error but when i run then i recieve runtime exceptions.

    Thanks
    kami

  7. #7
    Registered User
    Join Date
    Dec 2005
    Location
    Brazil
    Posts
    1,884

    Re: Development of mp3 player in J2ME

    Hi Kami,

    "...runtime exceptions"
    Once again, which exceptions? There is no way to anybody here to help you in case you do not provide more information.

    Best,
    Juarez Alvares Barbosa Junior - Brazil

  8. #8
    Registered User
    Join Date
    Jun 2007
    Posts
    28

    Re: Development of mp3 player in J2ME

    Hi,

    Thats right, when i run my code on Emulator(Wireless toolkit 2.5) then i receive this error message :

    ___________________________________________________

    Error creating inputstream/res/sound.WAV
    Unable to create MIDlet PlayerMidlet
    java.lang.IllegalArgumentException
    at javax.microedition.media.Manager.createPlayer(+11)
    at Source.<init>(+49)
    at PlayerMidlet.<init>(+214)
    at java.lang.Class.runCustomCode(+0)
    at com.sun.midp.midlet.MIDletState.createMIDlet(+34)
    at com.sun.midp.midlet.Selector.run(+22)
    _________________________________________________________



    hope you can help me now.

    Thanks
    kami

  9. #9
    Registered User
    Join Date
    Dec 2005
    Location
    Brazil
    Posts
    1,884

    Re: Development of mp3 player in J2ME

    Hi Kami,

    From the Javadocs:

    "java.lang.IllegalArgumentException
    Thrown to indicate that a method has been passed an illegal or inappropriate argument."


    However, AFAIK MMAPI (and WTK) support WAV files, so please try to debug this MIDlet (by setting some breakpoints) and see what is being passed to the methot at line 214 (if I am not mistaken, the error is happening there as pointed by the stack trace (at PlayerMidlet.<init>(+214)).

    Hope this helps!
    Juarez Alvares Barbosa Junior - Brazil

  10. #10
    Registered User
    Join Date
    Jun 2007
    Posts
    28

    Re: Development of mp3 player in J2ME

    hi Juarez,

    i tried this code by changing everything but i dont know whats happening here.

    the same exception i am receiving : i.e. IllegalArgumentException

    even i tried another code but same exception is here :
    here is the Code Listing:

    ___________________________


    import java.io.*;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.media.Manager;
    import javax.microedition.media.Player;

    public class SimplePlayer extends MIDlet {
    public void startApp() {
    try {

    Player player = Manager.createPlayer(getClass().getResourceAsStream("/sound.wav"),"audio/x-wav");
    player.start();

    }
    catch(Exception e) {
    e.printStackTrace();

    }
    }
    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    }


    _____________________________________________

    Now please tell me wats Wrong with this code :

    can you do me one favour please give me a simple code for developing music player through which we can play any media file(Wave,mp3 etc) so it might help me .

    as i am just trying to check what mistake i am doing.

    Thanks in advance
    Kami
    Last edited by atiqkamran; 2007-07-01 at 14:26.

  11. #11
    Registered User
    Join Date
    Dec 2005
    Location
    Brazil
    Posts
    1,884

    Re: Development of mp3 player in J2ME

    Hi Kami,

    Ok, then try this one:

    MIDP: Mobile Media API Example - Media Sampler
    http://www.forum.nokia.com/info/sw.n..._v1_0.zip.html
    Juarez Alvares Barbosa Junior - Brazil

  12. #12
    Registered User
    Join Date
    Jan 2010
    Posts
    5

    Re: Development of mp3 player in J2ME

    Dear juarezjunior,
    Can u please tell me,How to open this project in NetBeans IDE 6.5

  13. #13
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Development of mp3 player in J2ME

    Source(String fileName)
    {
    InputStream is = getClass().getResourceAsStream(fileName);

    if(is == null )
    {
    System.out.println("Error creating inputstream" + fileName);
    }
    Your error is most probably thrwon there...
    I think you might have a problem with the file you are trying to play... Could you try to place the file directly under your projects /src (or /source) directory ? And obviously change the code so that it references the file correctly ?

Similar Threads

  1. How to build a URL mp3 player?
    By kdwx in forum Symbian Media (Closed)
    Replies: 1
    Last Post: 2006-07-18, 12:00
  2. Has anybody been successful in making a MP3 player??
    By cindul in forum Symbian Media (Closed)
    Replies: 3
    Last Post: 2005-01-01, 07:35
  3. MP3 player
    By cindul in forum Symbian
    Replies: 0
    Last Post: 2004-12-30, 05:10
  4. Nokia N-Gage QD MP3 Player Application??
    By miaskuld in forum Audio
    Replies: 0
    Last Post: 2004-07-16, 02:33
  5. Game Development Nokia 7650 J2ME (MIDP&CDLC) Vs C++
    By hussain_qau in forum Mobile Java General
    Replies: 0
    Last Post: 2003-05-08, 08:35

Posting Permissions

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