playermidlet.java

来自「手机播放铃音示例」· Java 代码 · 共 74 行

JAVA
74
字号
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class PlayerMidlet extends MIDlet implements CommandListener,ItemStateListener {
	Display display;
	Command exitCommand = new Command("EXIT",Command.EXIT,99);
	Command stopCommand = new Command("Stop",Command.ITEM,1);
	Command startCommand = new Command("Start",Command.ITEM,1);
	Command rewindCommand = new Command("Rewind",Command.ITEM,2);
	
	Form form;
	Source source;
	Gauge gauge;
	int itemNum;
	
	public PlayerMidlet(){
		display = Display.getDisplay(this);
		
		form = new Form("MIDP 2.0 sound demo");
		form.addCommand(startCommand);
		form.addCommand(exitCommand);
		form.setCommandListener(this);
		
		gauge = new Gauge("player volume",true,100,50);
		form.append(gauge);
		gauge.setLayout(0x800);
		itemNum = form.append("value:"+gauge.getValue());
		form.setItemStateListener(this);
		
		source = new Source("/501120000001.wav");
	}
	protected void startApp() throws MIDletStateChangeException {
		display.setCurrent(form);
	}
	protected void pauseApp() {
		source.stop();
	}
	protected void destroyApp(boolean unconditional) throws MIDletStateChangeException{
		source.destroy();
	}
	public void itemStateChanged(Item item){
		if(item == gauge){
			source.setLevel(gauge.getValue());
			form.delete(itemNum);
			form.append("value:"+gauge.getValue());
		}
	}
	public void commandAction(Command c,Displayable s){
		if(c == stopCommand){
			source.stop();
			form.removeCommand(stopCommand);
			form.addCommand(startCommand);
			form.addCommand(rewindCommand);
		}
		else if(c == startCommand){
			source.start();
			form.removeCommand(startCommand);
			form.removeCommand(rewindCommand);
			form.addCommand(stopCommand);
		}
		else if(c == rewindCommand){
			source.rewind();
			form.removeCommand(rewindCommand);
		}
		else if(c == exitCommand) {
			try{
				destroyApp(false);
				notifyDestroyed();
			}
			catch(MIDletStateChangeException e){
			}
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?