📄 videoplayer_midlet.java
字号:
package ch11;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class VideoPlayer_MIDlet
extends MIDlet
implements CommandListener {
//声明一个Display对象
private Display display;
//声明一个Form对象
public Form form;
//声明一个获取视频文件地址TextField对象
private TextField textField;
//声明一个退出按钮Command对象
private Command exitCommand;
//声明一个播放按钮Command对象
private Command playCommand;
//声明一个类型支持按钮Command对象
private Command contentTypeCommand;
//声明一个代表装载视频文件进度的Gauge对象
private Gauge gauge;
//控制Gauge对象的变化速度
private static final int GAUGE_LEVELS = 4;
//声明Gauge对象的最大值
private static final int GAUGE_MAX = 12;
//声明视频文件的默认地址
private static final String DEFAULT_URL = "http://localhost/test.mpg";
/*
1.构造器
*/
public VideoPlayer_MIDlet() {
display = Display.getDisplay(this);
form = new Form("视频播放器");
textField = new TextField("视频地址", DEFAULT_URL, 100, TextField.ANY);
gauge = new Gauge("装载视频", false, GAUGE_MAX, 0);
exitCommand = new Command("退出", Command.EXIT, 2);
playCommand = new Command("播放", Command.SCREEN, 1);
contentTypeCommand = new Command("支持媒体类型", Command.SCREEN, 2);
form.addCommand(playCommand);
form.addCommand(exitCommand);
form.addCommand(contentTypeCommand);
form.setCommandListener(this);
form.append(textField);
display.setCurrent(form);
}
//启动应用程序
public void startApp() {
}
//挂起应用程序
public void pauseApp() {
}
//撤销应用程序
public void destroyApp(boolean unconditional) {
}
/*
2.响应按钮事件
*/
public void commandAction(Command c, Displayable s) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
else if (c == playCommand) {
gauge.setValue(0);
form.append(gauge);
VideoCanvas videoCanvas = new VideoCanvas(this);
videoCanvas.initializeVideo(textField.getString());
}
else if (c == contentTypeCommand) {
String url = textField.getString();
int position = url.indexOf(':');
String protocol = url.substring(0, position);
SupportedTypes typesUI = new SupportedTypes(this, protocol);
display.setCurrent(typesUI);
}
}
/*
3.更新进度条
*/
public void updateGauge() {
int current = gauge.getValue();
current = (current + GAUGE_MAX / GAUGE_LEVELS);
gauge.setValue(current);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -