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. Thanks for all your past and future contributions.

How to play sound in Java ME

From Wiki
Jump to: navigation, search
Article Metadata
Created: wang_shui (20 Mar 2007)
Last edited: hamishwillee (30 Jul 2013)

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.

Playing Sound

You need to import the following packages:


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");

The following code helps to play sound which is stored in a web server

Player p = Manager.createPlayer("http://server/sound.wav"); 

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);
InputStream in = hc.openInputStream();
Player p = Manager.createPlayer(is, "audio/X-wav");


  • When playing a multimedia file, you should always check if the used format is supported by the target device. To do this, you should use the Manager getSupportedContentTypes()
  • Also, you should always check which protocols are supported, by using Manager getSupportedProtocols() method

Related resources

This page was last modified on 30 July 2013, at 03:44.
97 page views in the last 30 days.