?? sound.java
字號:
package phone.mediaSound.play;
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.Ticker;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import phone.MediaSound;
public class Sound extends List implements CommandListener {
private Display display;
private Command cmdCancel, cmdOk, cmdStop, cmdBack;
private MediaSound ms;
private Player player;
private Ticker ticker;
private Form form;
public Sound(MediaSound ms, Display display) {
super("貝多芬鋼琴曲", List.IMPLICIT);
this.ms = ms;
this.display = display;
this.append("第三交響曲", null);
this.append("熱情奏鳴曲", null);
this.append("熱情奏鳴曲", null);
cmdCancel = new Command("cancel", Command.CANCEL, 1);
cmdOk = new Command("播放", Command.OK, 1);
this.addCommand(cmdCancel);
this.addCommand(cmdOk);
this.setCommandListener(this);
form = new Form("");
cmdStop = new Command("stop", Command.STOP, 1);
cmdBack = new Command("返回", Command.BACK, 1);
form.addCommand(cmdStop);
form.addCommand(cmdBack);
form.setCommandListener(this);
}
public void commandAction(Command command, Displayable dis) {
if (command == cmdStop) {
try {
player.stop();
player.close();
} catch (MediaException e) {
e.printStackTrace();
}
display.setCurrent(this);
}
if (command == cmdBack) {
try {
player.stop();
player.close();
} catch (MediaException e) {
e.printStackTrace();
}
display.setCurrent(this);
}
if (command == cmdOk) {
int select = this.getSelectedIndex();
if (select == 0) {
ticker = new Ticker("貝多芬.第三交響曲.mid");
form.setTicker(ticker);
display.setCurrent(form);
InputStream is = this.getClass().getResourceAsStream(
"/phone/mediaSound/play/musics/1.mid");
try {
player = Manager.createPlayer(is, "audio/midi");
player.realize();
player.start();
} catch (IOException e) {
e.printStackTrace();
} catch (MediaException e) {
e.printStackTrace();
}
}
if (select == 1) {
ticker = new Ticker("貝多芬.熱情奏鳴曲.mid");
form.setTicker(ticker);
display.setCurrent(form);
InputStream is = this.getClass().getResourceAsStream(
"/phone/mediaSound/play/musics/2.mid");
try {
player = Manager.createPlayer(is, "audio/midi");
player.realize();
player.start();
} catch (IOException e) {
e.printStackTrace();
} catch (MediaException e) {
e.printStackTrace();
}
}
if (select == 2) {
ticker = new Ticker("貝多芬.獻給愛麗絲二");
form.setTicker(ticker);
display.setCurrent(form);
InputStream is = this.getClass().getResourceAsStream(
"/phone/mediaSound/play/musics/3.mid");
try {
player = Manager.createPlayer(is, "audio/midi");
player.realize();
player.start();
} catch (IOException e) {
e.printStackTrace();
} catch (MediaException e) {
e.printStackTrace();
}
}
}
if (command == cmdCancel) {
ms.getMediaSound();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -