Miguel Salcedo
Miguel Salcedo

Reputation: 1

getSnapshot not supported on Blackberry

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

Upvotes: 0

Views: 796

Answers (2)

Nequita
Nequita

Reputation: 89

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

Upvotes: 0

Vitaliy Shibaev
Vitaliy Shibaev

Reputation: 1450

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()?

Upvotes: 2

Related Questions