Home J2me Audio MIDlet Example



Audio MIDlet Example
Posted on: November 5, 2008 at 12:00 AM
This example illustrates how to play audio songs in your mobile application by creating a MIDlet.

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("/kabhi-alvida-na-kehna.wav"), "audio/x-wav");
  p1.realize();

  p2 = Manager.createPlayer(getClass().getResourceAsStream("/aagepiche.wav"), "audio/x-wav");
  p2.realize();

  //p2.setTimeBase(p1.getTimeBase());

  p1.prefetch();
  p2.prefetch();

  p1.start();
  p2.start();

  }catch(IOException ioe){

  }catch(MediaException me){}
  }

  public void pauseApp(){}

  public void destroyApp(boolean unconditional){}
}

Download Source Code

Related Tags for Audio MIDlet Example:
javacapiantaudiotimemobileapplicationdiffiomediareadusingthisidappcreateeditplayerifforexampletoidledimidletexamidlebiboteilitaxmidllijavaximlayerinnodifferentasmntplaytrwancaletjadespimehowicrpprateratescatcreatingxaxampsvaxsocreatededitionatkishaimellmicrsongmpldiaeaandstrwantvatwssrenthavstatiapfeicaicapleplmindono


More Tutorials from this section

Ask Questions?    Discuss: Audio MIDlet Example   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.