?? playvideo.java
字號(hào):
import java.io.InputStream;
import javax.microedition.lcdui.Canvas;
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.Graphics;
import javax.microedition.lcdui.Item;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.VideoControl;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class PlayVideo extends MIDlet implements CommandListener {
private Display display;
Form form = new Form("視頻播放演示");
Command cmdPlayItem = new Command("通過(guò)Item播放", Command.SCREEN, 1);
Command cmdPlayCanvas = new Command("通過(guò)Canvas播放", Command.SCREEN, 1);
Command cmdExit = new Command("退出", Command.EXIT, 1);
Player player = null;
public PlayVideo() {
super();
String prop2 = System.getProperty("audio.encodings");
if (prop2 != null) {
System.out.println("照相機(jī)支持的圖像格式:"+prop2);
}
form.addCommand(cmdPlayItem);
form.addCommand(cmdPlayCanvas);
form.addCommand(cmdExit);
form.setCommandListener(this);
}
protected void startApp() throws MIDletStateChangeException {
display = Display.getDisplay(this);
display.setCurrent(form);
}
protected void pauseApp() {
close();
}
protected void destroyApp(boolean arg0)
throws MIDletStateChangeException {
close();
}
private void playItem() {
try {
InputStream is = getClass().getResourceAsStream("/test.mpg");
player = Manager.createPlayer(is,"Video/mpeg");
player.realize();
//獲得視頻控制器
VideoControl vc = (VideoControl)player.getControl("VideoControl");
Item item = (Item)vc.initDisplayMode(
VideoControl.USE_GUI_PRIMITIVE, null);
form.append(item);
player.start();
} catch(Exception e) {
e.printStackTrace();
}
}
private void playCanvas() {
try {
InputStream is = getClass().getResourceAsStream("/test.mpg");
player = Manager.createPlayer(is,"Video/mpeg");
player.realize();
MyCanvas mc = new MyCanvas();
//獲得視頻控制器
VideoControl vc = (VideoControl)player.getControl("VideoControl");
vc.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, mc);
display.setCurrent(mc);
player.start();
} catch(Exception e) {
e.printStackTrace();
}
}
class MyCanvas extends Canvas {
protected void paint(Graphics p) {
}
}
/**
* 命令按鈕事件
*/
public void commandAction(Command c, Displayable s) {
if (c == cmdExit) {
notifyDestroyed();
} else if (c == cmdPlayItem) {
display.setCurrent(form);
new Thread() {
public void run() {
playItem();
}
}.start();
}else if (c == cmdPlayCanvas) {
new Thread() {
public void run() {
playCanvas();
}
}.start();
}
}
private void close() {
if (player != null) {
player.close();
player = null;
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -