Home J2me Player Class in J2ME
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Player Class in J2ME

Advertisement
In J2ME, player class is used to play the .wav music, that is the only reason of using the class in our small application to create multimedia sounds.

Player Class in J2ME

     

Creating Multimedia Sound Using Player Class

In J2ME, player class is used to play the .wav music, that is the only reason of using the class in our small application to create multimedia sounds. It's required to import the javax.microedition.media package to use this class in our example. 

Please find the given methods and manager class that is used to create any multimedia sounds in J2ME..

Methods:

  • addPlayerListener(PlayerListener playerListener)
  • close()
  • deallocate()
  • getContentType()
  • getDuration()
  • getMediaTime()
  • getState()
  • prefetch()
  • realize()
  • removePlayerListener(PlayerListener playerListener)
  • setLoopCount(int count)
  • setMediaTime(long now)
  • start()
  • stop()

And the Manager class, that is having following Methods:

  • createPlayer(InputStream stream, String type)
  • createPlayer(String locator)
  • getSupportedContentTypes(String protocol)
  • getSupportedProtocols(String content_type)
  • playTone(int note, int duration, int volume)

Source Code of MultimediaSound.java

import javax.microedition.midlet.MIDlet;
import javax.microedition.media.*;

public class MultimediaSound extends MIDlet {
  public void startApp(){
  try {
  Player player = Manager.createPlayer(getClass().

  getResourceAsStream("/CatBird.wav"),"audio/x-wav");


  player.start();
  catch(Exception e) {
  e.printStackTrace();
  }
  }

  public void pauseApp() {}

  public void destroyApp(boolean unconditional) {}
}

Download Source Code

Advertisement

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 1, 2008

Ask Questions?    Discuss: Player Class in J2ME   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Amir
March 23, 2013
Urgent

I have written this code in Netbeans and it works but when I send my file to my cellphone it doesn't work,what should I do? Bests
DMCA.com