我想让我的j2me项目能够使用MMAPI(JSR135)进行拍照
所以我用以下代码检查我的HTC Diamond

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.midlet.MIDlet;

public class jsrtest extends MIDlet implements Runnable,CommandListener{
    Form form;
    Thread thread;
    Command c=new Command("Exit",Command.EXIT,0);
    public jsrtest()
    {
        Display.getDisplay(this).setCurrent(form=new Form("JSR Test"));
        form.addCommand(c);
        form.setCommandListener(this);
        (thread=new Thread(this)).start();
    }
    protected void destroyApp(boolean u){
        super.notifyDestroyed();
    }
    protected void pauseApp() {
    }
    protected void startApp(){
    }
    public void run() {
        checkJSR("MIDP2.0","javax.microedition.lcdui.game.GameCanvas");
        checkJSR("CLDC1.1","java.lang.Float");
        checkJSR("MMAPI","javax.microedition.media.Player");
        checkJSR("WMAPI","javax.wireless.messaging.Message");
        checkJSR("JSR75","javax.microedition.io.file.FileConnection");
        checkJSR("JSR082","javax.bluetooth.UUID");
        checkJSR("JSR135","javax.microedition.media.Control");
        checkJSR("JSR135_videocontrol","javax.microedition.media.control.VideoControl");
        checkJSR("JSR179","javax.microedition.location.Location");
        checkJSR("JSR180","javax.microedition.sip.SipConnection");
        checkJSR("JSR184","javax.microedition.m3g.Mesh");
        checkJSR("JSR211","javax.microedition.content.Registry");
        checkJSR("JSR226","javax.microedition.m2g.SVGImage");
        checkJSR("JSR229","javax.microedition.payment.TransactionRecord");
        checkJSR("JSR234","javax.microedition.amms.Module");
        checkJSR("JSR238","javax.microedition.global.Formatter");
        checkJSR("JSR239","javax.microedition.khronos.egl.EGL");
    }
    private void checkJSR(String jsr,String className)
    {
        try {
            Class.forName(className);
            form.append(jsr+" Supproted\n");
        } catch (ClassNotFoundException e) {
            form.append(jsr+" Not Supproted\n");
        }
    }
    public void commandAction(Command cmd, Displayable disp) {
        this.destroyApp(false);
    }
}


这表明HTC Diamond支持MMAPI。

因此,我在HTC Diamond上测试了以下代码,以查看相机是否正常运行但失败:

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));
       }
       p.start();
     }catch(Exception e){
        e.printStackTrace();
     }

}


在上面的代码上,可以在JAVA ME Platform SDK 3上正常工作。
谁能告诉我MMAPI为什么不能在我的手机上运行?

最佳答案

您可以进行其他测试以查看是否支持视频捕获:

if(System.getProperty("supports.video.capture") == null){
    //Video capture not supported
}


但我认为主要问题在于此:

form.append((Item)vc.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, null));


尝试这个:

    vc.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, <a Canvas here>);
    vc.setDisplayFullScreen(true);
    vc.setVisible(true);

08-17 20:13