[an error occurred while processing this directive]

Audio MIDlet Example


This example illustrates how to play audio songs in your mobile application by creating a MIDlet. In the application we have created a player for an audio song by using of javax.microedition.media API. As you know we have already created two player for two different songs and want to play both song in an application at a time.

Before creating of MIDlet we need the wav file in res folder which we are using in our MIDlet. In the application program, three methods are used of Player class, that are:

  • realize()
  • prefetch()
  • start()

The realize() method is used to Constructs portions of the Player without acquiring the scarce and exclusive resources, the prefetch() method is used to Acquires the scarce and exclusive resources and processes as much data as necessary to reduce the start latency and the start() method is used to Starts the Player as soon as possible.

The Application is as follows:

Source Code of AudioMIDlet.java

import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.midlet.*;
//import javax.microedition.media.TimeBase;

public class AudioMIDlet extends MIDlet{

  Player p1, p2;
  public void startApp(){
    try {

      p1 = Manager.createPlayer(getClass().getResourceAsStream(

      p2 = Manager.createPlayer(getClass().getResourceAsStream(




    }catch(IOException ioe){

    }catch(MediaException me){}

  public void pauseApp(){}

  public void destroyApp(boolean unconditional){}

Download Source Code


[an error occurred while processing this directive]