由于工作的需要,我今天简单的测试了一下摄像头的调用程序,代码的本身很简单。但是已经可以说明问题了。
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.StringItem;
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 SheXiangTou extends MIDlet {
Display dis;
private Form form;
private StringItem si;
public SheXiangTou() {
dis=Display.getDisplay(this);
form =new Form("test");
si=new StringItem("测试摄像头","");
form.append(si);
dis.setCurrent(form);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
test();
}
private void test(){
Player p;
VideoControl vc;
try{
p = Manager.createPlayer("capture://video");
p.realize();
vc = (VideoControl) p.getControl("VideoControl");
form.append(new StringItem("mmmmmmmm",""));
if (vc != null) {
form.append((Item)vc.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, null));//当前类继承了Form类
}
p.start();
}catch(Exception e){}
}
}