playing mp3 in j2me

hi, i am a developer in j2me, i tried to play a mp3 file in a midlet. but it is always calling an exception. the code is

try

{

Player p = Manager.createPlayer("http://www.indbazaar.com/Ratheesh/test.mp3");

p.setLoopCount(5);

p.start();

}

catch(IOException e)

{

System.out.println("Error in io : " + e.toString());

}

catch(MediaException e)

{

System.out.println("Error in media : " + e.toString());

}

the exception is Error in media : javax.microedition.media.MediaException : can not create a player for com/sun/mmedia/MP3Player, anyone pls help me

[646 byte] By [ratheesh_raveendran] at [2007-9-30 17:36:22]
# 1
Where are you testing this. The number of phones that supports playing MP3 files with MMAPI is quite low at the moment.shmoove
shmoove at 2007-7-6 14:04:48 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2
i tried this in j2me wireless toolkit 2.1, is the size of mp3 file a problem? the size of that mp3 is around around 6 MB, or any mp3 patent rule is there ?
ratheesh_raveendran at 2007-7-6 14:04:48 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3
Hi, I believe the emulators should also support MMAPI and mp3. please correct me if iam wrong.
prabhu_cbe at 2007-7-6 14:04:48 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 4

hi all

the content type for mp3 file is audio/mpeg

In the Manager class i used the method getSupportedContentTypes(), it will return an array of supported content types. In that this content type is not there!!!!

but video/mpeg is there, is it work?

in java docs they are saying MMAPI for MIDP 2.0 will play mp3 files also !!!

ratheesh_raveendran at 2007-7-6 14:04:48 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 5

Hello

I tried to do what you're doing right now and got the same error. The problem is that, although MMAPI is supposed to support MP3, J2ME doesn't, so you need a packet to decodificate mp3: JLayerME. I tried but it didn't work, but to be honest I didn't try again.

So take a look and if you succeed please let me know!!

Regards

donner02 at 2007-7-6 14:04:48 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 6

I know that this thread is old and maybe it has been resolved. I just wanted to add, just in case someone else is looking into playing mp3 files that I have mine working and I have tested on a Nokia 6620 but should work on any Nokia series 60. You folks can correct me if I am wrong but I believe that the cell phone is only required to support MIDP2.0 and this should work.

My code example below downloads the mp3 file from a website passing in a number of variables. Something like this:

http://www.mymp3.com/request.php?field1=1&field2=var&field3=rt700

This is suppose to return the actual mp3 file and the code below is how it handles it.

/*

* PlayerForm.java

*

* Created on August 30, 2005, 8:08 AM

*/

package ark;

import javax.microedition.lcdui.*;

import javax.microedition.media.*;

import javax.microedition.io.*;

import java.io.*;

import javax.microedition.media.control.VolumeControl;

import javax.microedition.io.HttpConnection;

import javax.microedition.io.Connector;

/**

*

* @author js

* @version

*/

public class PlayerForm extends Form implements CommandListener, ItemStateListener, Runnable

{

Display d = null;

List p = null;

String media = null;

Player player = null;

VolumeControl vc;

/**

* constructor

*/

public PlayerForm(Display _d, List _p, String c)

{

super("Media Player Preview");

//append("Sample Text Item");

try

{

d = _d;

p = _p;

media = c;

// Set up this form to listen to command events

setCommandListener(this);

// Set up this form to listen to changes in the internal state of its interactive items

setItemStateListener(this);

// Add the Exit command

addCommand(new Command("Stop", Command.EXIT, 0));

addCommand(new Command("Back", Command.EXIT, 1));

new Thread(this).start();

}

catch(Exception e)

{

d.setCurrent( new Alert("Error", e.getMessage(),null, AlertType.ERROR) );

}

}

public void run()

{

try

{

HttpConnection conn = (HttpConnection)Connector.open(media, Connector.READ_WRITE);

InputStream is = conn.openInputStream();

player = Manager.createPlayer(is,"audio/mpeg");

player.realize();

// get volume control for player and set volume to max

vc = (VolumeControl) player.getControl("VolumeControl");

if(vc != null)

{

vc.setLevel(100);

}

// the player can start with the smallest latency

player.prefetch();

// non-blocking start

player.start();

}

catch(Exception e)

{

d.setCurrent( new Alert("Error", e.getMessage(),null, AlertType.ERROR) );

}

}

/**

* Called when user action should be handled

*/

public void commandAction(Command command, Displayable displayable)

{

String s = command.getLabel();

if( s.equals("Back") )

{

d.setCurrent(p);

}

if( s.equals("Stop") )

{

try

{

player.stop();

}

catch(Exception e)

{

d.setCurrent( new Alert("Preview Error", e.getMessage(),null, AlertType.ERROR) );

}

}

}

/**

* Called when internal state of any item changed

*/

public void itemStateChanged(Item item)

{

}

}

Read through the run method which is called from the the constructor. The entire object is a class Form. I hope that this will help someone somewhere out there. :) Thanks.

Regards,

J

linuxwannbe@yahoo.com

LinuxPowered at 2007-7-6 14:04:48 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 7
hi,i don't think there is support for audio/mpeg alias mp3 code should work on theorybut it is not working in emulatorwhether it is midp2.0 or midp1.0 or cldc1.0/1.1if anybody actually played mp3 plz.. come forward with a solutionSailesh
sailesh_dit at 2007-7-6 14:04:48 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 8

I've never been able to play the mp3 or any sound through the simulator. but I have tested the above code on my cell phone which is Nokia 6620. The device or cell phone must either be:

CLDC1.0 or CLDC1.1

MIDP2.0

I'm working on testing the same logic on a Motorola i860 which is CLDC1.1 and MIDP2.0

But you are right, the actual playback does not work on a simulator. I don't know how to configure it in the simulator.

Hope this helps. Email anytime for more questions.

LinuxPowered at 2007-7-6 14:04:48 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 9
hi,there is tutorial and sample code from SonyEricsson but I don't think it's different from another MIDP2.0 devices. http://developer.sonyericsson.com/site/global/techsupport/tipstrickscode/java/p_playaudiomidp2.0.jsp have fun..cu
ApexDdorf at 2007-7-6 14:04:48 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 10
I agree. As long as the device supports MIDP2.0, you should be able to play mp3 files.
LinuxPowered at 2007-7-6 14:04:48 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 11

:-).. by the way , I tested it with emulator S700 from SonyEricsson.. And it worked just fine for me..

The next problem is, I want to read ID3-Tag from MP3 files and show it.. maybe the lyric for the song, too. I found several libs but they are just for J2SE not for J2ME.. How can I read ID3 Tag and Lyric?.. Someone any idea?.. Thanx..

Ciao..

ApexDdorf at 2007-7-6 14:04:48 > top of Java-index,Java Mobility Forums,Java ME Technologies...