Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Revision as of 10:51, 5 June 2009 by tanjaluodes (Talk | contribs)

How to play mp3 from server in Java ME

From Wiki
Jump to: navigation, search

The method below shows how an mp3 file can be played from a server in Java ME.

public void playAudio()
String url = "http://server/audio.mp3";
HttpConnection conn = (HttpConnection),
InputStream is = conn.openInputStream();
player = Manager.createPlayer(is,"audio/amr");
// get volume control for player and set volume to max
vc = (VolumeControl) player.getControl("VolumeControl");
if(vc != null)
catch(Exception e)

Note for S40 Devices: - The Midlet is responsible to avoid/catch out_of_memory exceptions in case the mp3 file

to be downloaded exceeds the amount of free memory.

- A good practice to avoid these kind of problems may be to either:

 - add the keyword <progressive_download: enable> as an attribute to the midlets jad or manifest file
 - change the url for the file to be downloaded to the format: 

resource://my_media_file.mp3?streamable=true In the case above this means: String url = "http://server/audio.mp3?streamable=true";

Applying one of the changes should result in streaming instead of first downloading the whole file and starting to play not before the complete file was downloaded.

116 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.