Java Tutorial/J2ME/mp3 — различия между версиями

Материал из Java эксперт
Перейти к: навигация, поиск
 
м (1 версия)
 
(нет различий)

Текущая версия на 05:00, 1 июня 2010

MetaData Control

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.rumand;
import javax.microedition.lcdui.rumandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.MetaDataControl;
import javax.microedition.midlet.MIDlet;
public class MetaDataControlMIDlet extends MIDlet implements CommandListener {
  private Display display = null;
  private List list = new List("Message", List.IMPLICIT);
  private Command exitCommand = new Command("Exit", Command.EXIT, 1);
  private Alert alert = new Alert("Message");
  private Player player = null;
  public MetaDataControlMIDlet() {
    display = Display.getDisplay(this);
    alert.addCommand(exitCommand);
    alert.setCommandListener(this);
    list.addCommand(exitCommand);
    list.setCommandListener(this);
    try {
      player = Manager.createPlayer(getClass().getResourceAsStream("/s.mp3"), "audio/mp3");
      player.prefetch();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  public void startApp() {
    if (player != null) {
      MetaDataControl mControl = (MetaDataControl) player
          .getControl("javax.microedition.media.control.MetaDataControl");
      if (mControl == null) {
        alert.setString("No Meta Information");
        display.setCurrent(alert);
      } else {
        String[] keys = mControl.getKeys();
        for (int i = 0; i < keys.length; i++) {
          list.append(keys[i] + " -- " + mControl.getKeyValue(keys[i]), null);
        }
        display.setCurrent(list);
      }
    }
  }
  public void commandAction(Command cmd, Displayable disp) {
    if (cmd == exitCommand) {
      notifyDestroyed();
    }
  }
  public void pauseApp() {
  }
  public void destroyApp(boolean unconditional) {
  }
}