?? videocanvas.java
字號:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import java.io.*;
/** Acquires the video content and renders it */
public class VideoCanvas extends Canvas implements CommandListener, PlayerListener, Runnable {
private VideoPlayer parent;
private Display display;
private Player player;
private VideoControl videoControl;
private String url;
private Thread initializer;
private Command close;
private Command rePlay;
public VideoCanvas(VideoPlayer parent){
super();
this.parent = parent;
display = Display.getDisplay(parent);
close = new Command("close", Command.SCREEN, 1);
addCommand(close);
setCommandListener(this);
}
public void initializeVideo(String url){
this.url = url;
initializer = new Thread(this);
initializer.start();
}
public void run(){
playVideo();
}
public void playVideo(){
String[] contentType=Manager.getSupportedContentTypes(null);
for(int i=0;i<contentType.length;i++)
{
System.out.println(contentType[i]);
}
try {
System.out.println("11");
try {
InputStream is = getClass().getResourceAsStream(url);
player = Manager.createPlayer(is, "video/mpeg");
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("222");
//player = Manager.createPlayer("/test.mpg");
player.addPlayerListener(this);
player.realize();
player.prefetch();
System.out.println("33");
videoControl = (VideoControl)player.getControl("VideoControl");
if (videoControl != null) {
videoControl.initDisplayMode(videoControl.USE_DIRECT_VIDEO, this);
}
int cHeight = this.getHeight();
int cWidth = this.getWidth();
videoControl.setDisplaySize(cWidth, cHeight);
display.setCurrent(this);
videoControl.setVisible(true);
player.start();
System.out.println("66");
} catch (MediaException me) {
Alert alert = new Alert("MediaException thrown", me.getMessage(), null, AlertType.ERROR);
display.setCurrent(alert);
}
}
/** Paints background color */
public void paint(Graphics g){
g.setColor(128, 128, 128);
g.fillRect(0, 0, getWidth(), getHeight());
}
public void playerUpdate(Player p, String event, Object eventData) {
//add "Replay" option when video is finished
if (event == PlayerListener.END_OF_MEDIA)
{
if (rePlay == null)
{
rePlay = new Command("re-play", Command.SCREEN, 1);
addCommand(rePlay);
}
}
}
public void commandAction(Command c, Displayable s) {
if(c == rePlay){
try{
player.start();
} catch (MediaException me) {
Alert alert = new Alert("MediaException thrown", me.getMessage(), null, AlertType.ERROR);
display.setCurrent(alert);
}
}
else if(c == close){
player.close();
parent.form.delete(1);
display.setCurrent(parent.form);
url=null;
parent=null;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -