Player Event : Audio Player « J2ME « Java Tutorial






import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.PlayerListener;
import javax.microedition.midlet.MIDlet;

public class EchoEventsMIDlet extends MIDlet implements PlayerListener {

  private StringItem stringItem = new StringItem("", null);

  public void startApp() {
    try {
      Form form = new Form("Player State");
      form.append(stringItem);
      Display.getDisplay(this).setCurrent(form);

      Player player = Manager.createPlayer(getClass().getResourceAsStream("/b.wav"), "audio/x-wav");
      player.addPlayerListener(this);

      player.start();

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

  public void pauseApp() {
  }

  public void destroyApp(boolean unconditional) {
  }

  public void playerUpdate(Player player, String event, Object eventData) {
    stringItem.setText(event);
    System.err.println(event);
  }
}








31.54.Audio Player
31.54.1.Audio Player Demo
31.54.2.Cached Audio Player
31.54.3.Wav file player
31.54.4.Player Event
31.54.5.implements PlayerListener
31.54.6.Network Player Manager
31.54.7.Load WAV file from a web site