Categories: Java | Java ME | How To | Code Examples | Multimedia | Audio
This page was last modified 14:54, 5 December 2007.
How to play mp3 from server in Java ME
From Forum Nokia Wiki
The method below shows how an mp3 file can be played from a server in Java ME.
public void playAudio() { try { String url = "http://server/audio.mp3"; HttpConnection conn = (HttpConnection)Connector.open(url, Connector.READ_WRITE); InputStream is = conn.openInputStream(); player = Manager.createPlayer(is,"audio/amr"); 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) {} } </code java> 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 or - 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.
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem with media API | felixksp | Mobile Java General | 9 | 2007-05-21 20:07 |
| mp3 2 aac | tmpx | General Discussion | 18 | 2004-08-05 07:52 |
| How to tell where exactly my code runs on the OMAP? | koli_bg | Symbian Media (Graphics & Sounds) | 17 | 2007-02-19 11:03 |
| Please give me some hints about mixing sound to uplink | goodtaste | Audio | 3 | 2007-02-11 02:20 |
| Mp3 ringtones | dcwood | General Discussion | 0 | 2004-07-02 09:38 |
