Player Class in J2ME

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

Ads