大家帮帮我,一个关于视频播放的问题
我想试试播放视频的程序
程序如下:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import java.util.Vector;
import java.io.*;
public class test extends MIDlet implements CommandListener,Runnable{
private Command exitCommand = new Command("退出",Command.EXIT,1);
private Command playCommand = new Command("播放",Command.ITEM,1);
private Display display;
private List mMainScreen;
private Form myForm;
public test(){
myForm = new Form("WindowsMediaPlayer");
}
public void startApp(){
display = Display.getDisplay(this);
if(mMainScreen==null){
mMainScreen = new List("视频播放",List.IMPLICIT);
mMainScreen.append("资源获取",null);
mMainScreen.addCommand(playCommand);
mMainScreen.addCommand(exitCommand);
mMainScreen.setCommandListener(this);
}
display.setCurrent(mMainScreen);
}
public void pauseApp(){}
public void destroyApp(boolean u){}
public void run(){
playFromResource();
}
public void commandAction(Command c,Displayable s){
if(c==exitCommand){
notifyDestroyed();
}else if(c==playCommand){
Form waitForm = new Form("正在下载...");
display.setCurrent(waitForm);
Thread t = new Thread(this);
t.start();
}
}
private void playFromResource(){
try{
InputStream in = getClass().getResourceAsStream("/1.mpg");
Player player = Manager.createPlayer(in,"video/mpeg");
player.realize();
VideoControl vc = (VideoControl)player.getControl("VideoControl");
Item it = (Item)vc.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE,null);
myForm.append(it);
player.start();
}catch(Exception e){System.out.println("error");}
myForm.addCommand(exitCommand);
display.setCurrent(myForm);
}
}
但是一点击播放加载一会儿,模拟器就关闭了,不知是怎么回事。希望指教