Categories: Java | Java ME | How To | Code Examples | Multimedia | Audio
This page was last modified 18:17, 18 January 2008.
How to Play sound in Java ME
From Forum Nokia Wiki
You need to import the following packages:
import java.io.*; import javax.microedition.media.*;
The following code helps to play sound which is embedded in your jar file
InputStream is = getClass().getResourceAsStream("sound.wav"); Player p = Manager.createPlayer(is, "audio/X-wav"); p.start();
The following code helps to play sound which is stored in a web server
Player p = Manager.createPlayer("http://server/sound.wav"); p.start();
You may also try other sound formats by minor changing ie; by changing the mime type.
Also you have to keep in mind while giving the url in the second case, use of special characters like '&' etc are not supported. In such case you should follow the following method
HttpConnection hc = (HttpConnection) Connector.open(url); InputStream in = hc.openInputStream(); Player p = Manager.createPlayer(is, "audio/X-wav"); p.start();
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| example code from knowledge base crashes? | Nokia_Archive | General Symbian C++ | 1 | 2002-05-29 09:35 |
| Disabling key click tone (Series 60) | Nectaris | Mobile Java Media (Graphics & Sounds) | 1 | 2006-09-20 22:29 |
| Sound class not supported on Nokia 7650? | Captain P | Mobile Java Media (Graphics & Sounds) | 4 | 2006-11-03 15:55 |
| Sound from a J2ME app on the 7650 | LongSteve | Mobile Java General | 4 | 2002-09-04 05:58 |
| Nokia UI problem | adamkooo | Mobile Java Media (Graphics & Sounds) | 5 | 2005-12-02 21:14 |
