MMAPI (JSR 135) allows Java ME applications to easily access MultiMedia functionalities, like playing and recording both video and audio data. This article shows the steps required to play a sound, from both local and network resources.
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();
No related wiki articles found