MMAPI supports playing mp3 files. Depending upon the device capabilities and size of the mp3 files, an MP3 player can be created on J2ME phones.

You should note that not all phones support MP3 audio format. For eexample, Motorola/A1000 supports midi but not mp3 while E1000 supports both.

The method below creates player and play mp3 file.

 public void run()
{
  try
  {
    InputStream is = getClass().getResourceAsStream("/your.mp3");
    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);
    }
    player.prefetch();
    player.start();
  }
  catch(Exception e)
  {}
}

 

 

 

 Related Tips