2010-09-07 8 views
0

Je rencontre des problèmes lors de la prise de vue en utilisant la méthode VideoControl.getSnapshot(). Il lance toujours l'exception: getSnapshot non pris en charge. J'utilise JRE 5.0.0 avec Eclipse et BlackBerry® Java® SDK 5.0 Plugin. Ce que je fais d'abord est de lister l'encodage supporté par Blackberry SmartPhone sélectionné (bold 9700) avec la commande System.getProperty ("video.snapshot.encodings") et de sélectionner un encodage dans la liste et de le passer comme getSnapshot argument.getSnapshot non pris en charge sur Blackberry

J'ai testé sur plusieurs Blackberry et la même exception est levée.

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

Répondre

3

Je ne sais pas ma réponse est réelle après plus d'une moitié de l'année, mais peut-être qu'il sera utile.

Vous pouvez essayer d'utiliser Thread.sleep (1000); avant l'appel getSnapshot(). Le problème peut être lié à ce fait: "le viseur doit être visible sur l'écran avant d'appeler getSnapShot()". Par conséquent, si vous appelez getSnapshot immédiatement après

UiApplication.getUiApplication().pushScreen(new TempScreen(cameraView));
, l'appareil photo n'est pas prêt pour la prise de vue suivante.

Etes-vous vraiment sûr que l'API getSnapshot() est prise en charge exactement sur votre appareil? Certains fabricants peuvent ne pas le supporter, bien que l'API définisse cette méthode. Avez-vous exécuté System.getProperty ("video.snapshot.encodings") exactement sur le même périphérique que celui où vous avez testé getSnapshot()?

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