Home J2me Audio MIDlet Example

Related Tutorials


 
 

Share on Google+Share on Google+

Audio MIDlet Example

Advertisement
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

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 5, 2008

Related Tutorials

Discuss: Audio MIDlet Example   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:2
sai
August 28, 2012
how to play the back ground sound in a form

ok
yitayew
November 19, 2012
dear

it is nice site.
DMCA.com