2010-09-07 111 views
0

我在使用VideoControl.getSnapshot()方法拍照时出现问题。它总是抛出异常:getSnapshot不受支持。我在Eclipse和BlackBerry®Java®SDK 5.0插件上使用JRE 5.0.0。getSnapshot黑莓手机不支持

我所做的第一件事是用命令System.getProperty(“video.snapshot.encodings”)列出黑莓智能手机支持的编码(粗体9700),并从列表中选择一种编码并将其作为getSnapshot传递论据。

我测试过几款黑莓手机,并且抛出了相同的异常。代码

部分:

mPlayer = Manager.createPlayer("capture://video?encoding=video/3gpp"); 

mPlayer.realize(); 

mPlayer = Manager.createPlayer("capture://video?encoding=video/3gpp"); 

mPlayer.start(); 

videoControl = (VideoControl)mPlayer.getControl("VideoControl"); 

Field cameraView = (Field) videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field"); 

Thread.sleep(1000); 

UiApplication.getUiApplication().pushScreen(new TempScreen(cameraView)); 

byte[] snapShot = videoControl.getSnapshot("encoding=jpeg&width=480&height=360&quality=superfine"); 

Bitmap image = Bitmap.createBitmapFromBytes(snapShot, 0, snapShot.length, 1); 

UiApplication.getUiApplication().pushScreen(new TempScreen(image)); 

}catch (MediaException e){ 
UiApplication.getUiApplication().pushScreen(new TempScreen("Exception: " + e.getMessage())); } 

catch (IOException e){ 
UiApplication.getUiApplication().pushScreen(new TempScreen("IO Exception: " + e.getMessage())); 
} 

catch (InterruptedException e){UiApplication.getUiApplication().pushScreen(new TempScreen("Interrupted Exception: "+ e.getMessage()));} 

回答

3

不知道是我的答案是后实际超过一年半的时间,但可能会是有用的。

您可能会尝试使用Thread.sleep(1000); getSnapshot()调用之前。 问题可能与这个事实有关:“在调用getSnapShot()之前,取景器实际上必须在屏幕上可见。”

因此,如果您在

UiApplication.getUiApplication().pushScreen(new TempScreen(cameraView));
之后立即致电getSnapshot,则相机未准备好拍摄下一张照片。

您是否确定getSnapshot()API完全支持您的设备?尽管API定义了这种方法,但有些制造商可能不支持它。您是否在测试getSnapshot()的相同设备上正确运行System.getProperty(“video.snapshot.encodings”)?

0
Player _p; 
    VideoControl _vc ; 
    RecordControl _rc ; 
    String PATH; 
    FileConnection fileconn; 
    Object canvas= new Object(); 

    public static boolean SdcardAvailabulity() { 
     String root = null; 
     Enumeration e = FileSystemRegistry.listRoots(); 
     while (e.hasMoreElements()) { 
      root = (String) e.nextElement(); 
      if(root.equalsIgnoreCase("sdcard/")) { 
       return true; 
      }else if(root.equalsIgnoreCase("store/")) { 
       return false; 
      } 
     } 
     class MySDListener implements FileSystemListener { 
      public void rootChanged(int state, String rootName) { 
       if(state == ROOT_ADDED) { 
        if(rootName.equalsIgnoreCase("sdcard/")) { 
        } 
       } else if(state == ROOT_REMOVED) { 
       } 
      } 
     } 
     return true; 
    } 
protected boolean invokeAction(int action){ 
     boolean handled = super.invokeAction(action); 
     if(SdcardAvailabulity()){ 
      PATH = System.getProperty("fileconn.dir.memorycard.videos")+"Video_"+System.currentTimeMillis()+".3gpp";//here "str" having the current Date and Time; 
     } else { 
      PATH = System.getProperty("fileconn.dir.videos")+"Video_"+System.currentTimeMillis()+".3gpp"; 
     } 
     if(!handled){ 
      if(action == ACTION_INVOKE){ 
       try{  

        if(_p!=null) 
         _p.close(); 
       }catch(Exception e){ 
       } 
      } 
     } 
    return handled; 
    } 
    public MyScreen(){ 
     setTitle("Video recording demo"); 
     ButtonField AddPhoto = new ButtonField("push",ButtonField.FOCUSABLE | ButtonField.FIELD_HCENTER | ButtonField.FIELD_VCENTER | DrawStyle.HCENTER | ButtonField.NEVER_DIRTY | Field.USE_ALL_WIDTH); 
     FieldChangeListener PhotoListener = new FieldChangeListener() { 
      public void fieldChanged(Field field, int context) { 
       ButtonField Button = (ButtonField) field; 
       if (Button.getLabel().equals("push")){ 


       } 
      } 
     }; 
     AddPhoto.setChangeListener(PhotoListener); 
     add(AddPhoto); 
    } 
}