implements PlayerListener : Audio Player « J2ME « Java Tutorial






import javax.microedition.lcdui.StringItem;
import javax.microedition.media.Player;
import javax.microedition.media.PlayerListener;
import javax.microedition.media.control.VolumeControl;

public class EventHandler implements PlayerListener {
  private StringItem item;

  public EventHandler(StringItem item) {
    this.item = item;
  }

  public void playerUpdate(Player player, String event, Object eventData) {
    if (event == (PlayerListener.VOLUME_CHANGED)) {
      VolumeControl vc = (VolumeControl) eventData;
      updateDisplay("Volume Changed to: " + vc.getLevel());
      if (vc.getLevel() > 60) {
        updateDisplay("Volume higher than 60 is too loud");
        vc.setLevel(60);
      }
    } else if (event == (PlayerListener.STOPPED)) {
      updateDisplay("Player paused at: " + (Long) eventData);
    } else if (event == (PlayerListener.STARTED)) {
      updateDisplay("Player started at: " + (Long) eventData);
    } else if (event == (PlayerListener.END_OF_MEDIA)) {
      updateDisplay("Player reached end of loop.");
    } else if (event == (PlayerListener.CLOSED)) {
      updateDisplay("Player closed.");
    } else if (event == (PlayerListener.ERROR)) {

      updateDisplay("Error Message: " + (String) eventData);
    }
  }

  public void updateDisplay(String text) {
    item.setText(text);
    System.err.println(text);
  }
}








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