Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何让Codenameone捕获视频?_Codenameone - Fatal编程技术网

如何让Codenameone捕获视频?

如何让Codenameone捕获视频?,codenameone,Codenameone,我正在使用以下代码尝试使用codenameone 2.0捕获视频 tProperty.setHint("name the property that is a media"); final CheckBox cbVideo = new CheckBox("Video"); final Button bCapture = new Button("Capture Media"); final MediaPlayer mpPlayer =

我正在使用以下代码尝试使用codenameone 2.0捕获视频

        tProperty.setHint("name the property that is a media");
        final CheckBox cbVideo = new CheckBox("Video");
        final Button bCapture = new Button("Capture Media");
        final MediaPlayer mpPlayer = new MediaPlayer();
        bCapture.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ect){
                try {
                    if (cbVideo.isSelected()) {
                        String value = Capture.captureVideo();
                        mpPlayer.setDataSource(value);
                        mpPlayer.setName(tProperty.getText());
                    }else {
                        String value = Capture.captureAudio();
                        mpPlayer.setDataSource(value);
                        mpPlayer.setName(tProperty.getText());

                    }
                }catch (Exception e){

                }
            }
        });
        cM.addComponent(tProperty);
        cM.addComponent(cbVideo);
        cM.addComponent(bCapture);
        cM.addComponent(mpPlayer);
        Command [] cmds = new Command[1];
        cmds[0] = new Command("Done") {
            public void actionPerformed(ActionEvent evt) {
                //do Option1
            }        
        };
           Dialog.show(editType, cM, cmds);            
在模拟器中运行时,单击CaptureMedia按钮,将显示文件选择器界面。但是,我无法选择任何文件,无论是音频还是视频,因为“选择文件”按钮被禁用。
如何在模拟器中测试视频捕获?

在Codename One模拟器中播放本地视频时会出现倒退,尽管它应该可以在设备上工作。Codename One的下一次更新将修复它,但是现在你可以通过从一个流中播放来解决它,这个流应该可以正常工作


只需使用
FileSystemStorage
类获取视频的
InputStream
,并调用相应的播放代码。请注意,这比通过URL API播放效率要低,因此在修复回归后,您可能应该返回基于URL的API。

我认为这是一个布局问题,您在创建视频之前添加了MediaPlayer组件,因此它的首选大小为0。 尝试将视频放置在边框布局中心,以便忽略其首选大小,播放器将有足够的显示空间

试试这个:

    final Form hi = new Form("Hi World");
    hi.setLayout(new BorderLayout());

    final Button bCapture = new Button("Capture Media");
    bCapture.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ect) {
            try {
                final MediaPlayer mpPlayer = new MediaPlayer();
                String value = Capture.captureVideo();
                System.out.println("Captured Video " + value);
                if (value != null) {
                    System.out.println("Playing Video");
                    InputStream is = FileSystemStorage.getInstance().openInputStream(value);
                    String strMime = "video/mp4";
                    System.out.println("Input Stream" + is.available());
                    mpPlayer.setName("bla");
                    mpPlayer.setDataSource(is, strMime, new Runnable() {
                        public void run() {
                            System.out.println("reset the clip for playback");
                        }
                    });
                    hi.addComponent(BorderLayout.CENTER, mpPlayer);
                    hi.revalidate();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    );
    hi.addComponent(BorderLayout.NORTH, bCapture);

    hi.show();

其实这不是问题。问题是模拟器正在寻找一个音频文件,而我认为它应该根据cbVideo.isSelected()查找视频。现在修好了,别那么快。仍然无法在模拟器中播放视频。它被捕获到一个文件中,但播放机报告该文件不存在,并给出java.io.FileNotFoundException:/Users/jamesagada/.cn1/_var_folders\uu j_xsgymcmd1lsc5zqtg65ctlsm0000gn_T_temp6413969854734503786.mp4(没有这样的文件或目录)。我尝试了这个方法,但它什么都没有做。文件系统存储说该文件不存在!您始终需要提供文件系统存储API的完整路径,并使用如下主目录/Users/jamesagada/.cn1/_var_folders\u j_xsgymcmd1lsc5zqtg65ctlsm0000gn\u T_temp64139‌​69854734503786.mp4?这是Capture.captureVideo()中的值。或者我应该使用另一个命令?不确定。除了进行eclipse插件更新之外,我将如何做到这一点?谢谢陈。你是对的。我必须添加mpPlayer.setPreferredH(Display.getInstance().getDisplayHeight()/2);让它工作。