Playing local MP3

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)
{}
}

9 comments:

  1. Here you have given relative path which folder it corresponds to ?

    ReplyDelete
  2. it corresponds to resource folder

    ReplyDelete
  3. is there any one found some one that have used this code and fulfill their targets? this code is more popular but may not work.

    ReplyDelete
  4. it's not work.. please.. i have try anything to play.. but "audio/mpeg" is not work. Else, i've try "audio/mp3", "audio/mpeg-layer3"..

    Please give THE RIGHT CODE!!

    ReplyDelete
  5. On my n6210 it works correctly. First of all you must check if getClass().getResourceAsStream("/your.mp3"); doesn't return null (maybe path is incorrect, try without "/"). Secondly check what formats you phone supports: String[] contents = Manager.getSupportedContentTypes(null);
    Maybe you device doesn't support "audio/mpeg";

    ReplyDelete
  6. Cannot find installation of quicktime.
    This error is there.

    how to overcome this?

    ReplyDelete
  7. can you give me the full code..??
    i am new in j2me..

    ReplyDelete
  8. Oh no, please explain how to use, i've just seen this snippet at java-tips.org but cant make it work @@

    ReplyDelete

 

Design by Blogger Buster | Distributed by Blogging Tips