Blackberry 不支持 getSnapshot

发布于 2024-09-17 22:41:39 字数 1468 浏览 1 评论 0原文

我在使用 VideoControl.getSnapshot() 方法拍照时遇到问题。它总是抛出异常:getSnapshot not Supported。我将 JRE 5.0.0 与 Eclipse 和 BlackBerry® Java® SDK 5.0 插件结合使用。

我首先要做的是使用命令 System.getProperty("video.snapshot.encodings") 列出所选 Blackberry SmartPhone 支持的编码(粗体 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()));}

I'm having problem when taking a picture using VideoControl.getSnapshot() method. It always throw the exception: getSnapshot not Supported. I'm using JRE 5.0.0 with Eclipse and BlackBerry® Java® SDK 5.0 Plugin.

What I do first is to list the encoding supported by Blackberry SmartPhone selected (bold 9700) with the command System.getProperty("video.snapshot.encodings") and select one encoding from the list and pass it as the getSnapshot argument.

I've tested on several Blackberry and the same exception is thrown.

Part of the code:

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()));}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心意如水 2024-09-24 22:41:39

不确定我的答案在半年多后是否真实,但可能会有用。

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

因此,如果您在之后立即调用 getSnapshot

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

the camera isn't prepared for the next shot.

另外,您真的确定您的设备完全支持 getSnapshot() API 吗?尽管 API 定义了此方法,但某些制造商可能不支持它。您是否在测试 getSnapshot() 的同一设备上运行 System.getProperty("video.snapshot.encodings") ?

Not sure is my answer is actual after more than a half of year, but may be it will be useful.

You may try to use Thread.sleep(1000); before getSnapshot() call.
The problem may be related with that fact: "viewfinder must actually be visible on the screen prior to calling getSnapShot()."

So if you call getSnapshot immediately after

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

the camera isn't prepared for the next shot.

Also are you really sure that getSnapshot() API is supported exactly on your device? Some manufacturers may not support it, despite the API defines this method. Did you run System.getProperty("video.snapshot.encodings") exactly on the same device where you test getSnapshot()?

月牙弯弯 2024-09-24 22:41:39
  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);
  }
}
  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);
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文