Playing media in J2ME
The simplest MMAPI MIDlet that can be built allows you to easily play a multimedia file from within your MIDlet without worrying about controls, feature sets, or security architecture. If all you’re doing is adding some sampled audio (or any other media) in a game, MMAPI allows you to do so in two lines of code. Listing below shows this code within a complete MIDlet. //A Simple MMAPI MIDlet import javax.microedition.midlet.MIDlet; import javax.microedition.media.Manager; import javax.microedition.media.Player; public class SimplePlayer extends MIDlet { public void startApp() { try { Player player = Manager.createPlayer(getClass().getResourceAsStream("/media/audio/chapter3/baby.wav"),"audio/x-wav"); player.start(); } catch(Exception e) { e.printStackTrace(); } } public void pauseApp() { } public void destroyApp(boolean unconditional) { } } To keep things simple at this stage, the media file is played by creating an InputStream on a wav file, which is embedded in the ...