2012-11-05 3 views
-1

내 응용 프로그램에 amd save a video를 기록하고 싶습니다. 포럼에 많은 정보가 없습니다.Blackberry 응용 프로그램에 비디오 녹화하기

"Invoke.invokeApplication (Invoke.APP_TYPE_CAMERA, new CameraArguments());"와 같은 카메라를 호출하고 싶지 않습니다.

다음과 같은 코드가 나에게 http://docs.blackberry.com/en/developers/deliverables/17968/Record_video_to_a_file_in_a_BB_device_app_1222784_11.jsp

내가 시작, 중지 내가하려고하면 비디오를 저장하고 "지원되지 않는 포맷"라는 비디오를 재생까지 와서 빈 화면을 제공합니다이며, 지원되는 모든 형식을 얻을 수있는 방법이 있으며 모든 비디오 형식의 목록이 있습니까? 내 코드 : 내가 실수를 할 경우

public class MyScreen extends MainScreen{ 
String PATH; 
RecordControl _recordControl; 
Player _player; 
MenuItem RecordVideo; 
MenuItem StopVideo; 
MenuItem SaveVideo; 

    public MyScreen() { 
    try { 
     _player = javax.microedition.media.Manager.createPlayer("capture://video?encoding=video/3gpp"); 
     _player.realize(); 
     VideoControl videoControl = (VideoControl) _player.getControl("VideoControl"); 
     _recordControl = (RecordControl) _player.getControl("RecordControl"); 
     Field videoField = (Field) videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field"); 
     try{ 
      videoControl.setDisplaySize(Display.getWidth(), Display.getHeight()); 
     }catch(MediaException me){ 
      Dialog.alert("Display size not supported"); 
     } 
     add(videoField); 
     _recordControl.setRecordLocation("file:///store/home/user/videos/VideoRecordingTest.3gpp"); 
     _player.start(); 
     _recordControl.startRecord();  
    }catch(IOException e){ 
     Dialog.alert(e.toString()); 
    } catch(MediaException e){ 
     Dialog.alert(e.toString()); 
    } 
    RecordVideo = new MenuItem("Start Recording", 0, 0){ 
     public void run() { 
      try { 
       _player.start(); 
       _recordControl.startRecord(); 
      } catch (MediaException e) { 
       Dialog.alert("Error Starting recording"); 
       e.printStackTrace(); 
      } 
     } 
    }; 
    StopVideo = new MenuItem("Stop Recording", 0, 0){ 
     public void run() { 
      try { 
       _player.stop(); 

      } catch (MediaException e) { 
       Dialog.alert("Error Stopping recording"); 
       e.printStackTrace(); 
      } 
     } 
    }; 
    SaveVideo = new MenuItem("Save Video", 0, 0){ 
     public void run() { 
      try { 
       // Create an invocation instance with the specified URL where the file type is one of the media types supported by the media player. 
       Invocation invocation = new Invocation("file:///SDCard/BlackBerry/music/001.mp3"); 

       // Get the Registry object using the class name of the application  
       Registry _registry=Registry.getRegistry(Application.getApplication().getClass().getName()); 

       //Invoke the content handler. 
       _registry.invoke(invocation); 
      } catch (IOException e) 
      {  } 

     } 
    }; 
} 
public void stop() { 
    if (_player != null){ 
      _player.close(); 
      _player = null; 
    } 

    if (_recordControl != null){ 
     _recordControl.stopRecord(); 
     try { 
      _recordControl.commit(); 
     } 
     catch (Exception e) 
     { 
      Dialog.alert(e.toString()); 
     } 
     _recordControl = null; 
    } 
} 
protected void makeMenu(Menu menu, int instance) { 
     ContextMenu contextMenu = ContextMenu.getInstance(); 
     contextMenu.setTarget(this); 
     contextMenu.clear(); 
     this.makeContextMenu(contextMenu); 
     menu.deleteAll(); 
     menu.add(contextMenu); 
    } 

    public void makeContextMenu(ContextMenu contextMenu) { 
     contextMenu.addItem(MenuItem.separator(32)); 
     contextMenu.addItem(RecordVideo); 
     contextMenu.addItem(StopVideo); 
     contextMenu.addItem(SaveVideo); 
    } 

} 
+1

남자는, 메뉴 저장 항목은 정말뿐만 아니라 저장되지는 ​​비디오 파일에 일부 관련이없는을 열려고한다. 내가 주석 섹션없이 깨끗한 코드를보고 싶습니다 –

답변

0

@Eugen 마르티노, 그것에 대해 죄송합니다, 다음 시간을 기억하고 깨끗한 코드를 게시하려고합니다는, 개발, STIL 새로운 날 맨 손으로 해 주시기 바랍니다. @Miguel 죄송합니다, Didntknow 링크 레코딩,을 stoping를 들어

전체 코드와 비디오를 저장하기위한 sollutions로 anwers, 감사를 받아 들일뿐만 아니라 비디오를 종료하는 방법 :

도우미 :

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

메인 클래스

String _encoding = "encoding=video/3gpp&mode=standard"; 
private static Player _player; 
private static VideoControl _vc; 
private RecordControl _rc; 
private static boolean _locationSet = false; 
private static OutputStream _out; 
private static FileConnection _fc; 
String PATH; 
String STREAM_VIDEO_FILE; 
String StringVideofileName; 
/*LabelField GetVideofileName = new LabelField("",LabelField.FOCUSABLE){ 
    protected boolean navigationClick(int status, int time){ 
     Dialog.alert("Clicked"); 
     return true; 
    } 
};*/ 
protected boolean keyChar(char c, int status, int time){ 
    switch(c) { 
     case 's': 
      startRecord(); 
      return true; 
     case 'x': 
      stopRecord(); 
      return true; 
     case 'c': 
      commit(); 
      return true; 
     default: 
      return false; 
    } 
} 
private void startRecord(){ 
    try { 
     if(!_locationSet){  
      try { 
       System.out.println("STREAM_VIDEO_FILE-------------"+STREAM_VIDEO_FILE); 
       _fc = (FileConnection)Connector.open(STREAM_VIDEO_FILE); 

       if(!_fc.exists()){ 
        _fc.create(); 
       }        
       _fc.truncate(0);       
       _out = _fc.openOutputStream(); 
      } catch (Exception e) { 
       return; 
      } 
      _rc.setRecordStream(_out); 
      _locationSet = true; 
     }    
     _rc.startRecord(); 
    } catch (Exception e) { 
    } 
} 
private void stopRecord(){ 
    try {    
     _rc.stopRecord(); 
    } catch (Exception e) { 
    } 
} 
private void commit() { 
    try {   
     _rc.commit(); 
     Dialog.alert("Saved"); 
     _locationSet = false; 
     try { 
      _out.close(); 
      _fc.close(); 
      StringVideofileName =_fc.getName(); 
      DefaultScreen.LF.setText(StringVideofileName); 
      if(_player!=null) 
       _player.close();   
     }catch(Exception e){ 
      if(_player!=null){ 
       _player.close(); 
      } 
      if(_fc!=null){ 
       try{ 
        _fc.close(); 
       }catch (IOException e1){ 
       } 
      }      
     } 
    } catch (Exception e) { 
    } 
} 
public MyScreen(){ 
    if(Sh.SdcardAvailabulity()){ 
     PATH = System.getProperty("fileconn.dir.memorycard.photos")+"Video_"+System.currentTimeMillis()+".mp4";//here "str" having the current Date and Time; 
    } else { 
     PATH = System.getProperty("fileconn.dir.photos")+"Video_"+System.currentTimeMillis()+".mp4"; 
    } 
    STREAM_VIDEO_FILE = PATH; 
    try {   
     _player = javax.microedition.media.Manager.createPlayer("capture://video?" + _encoding);    
     _player.start(); 
     _vc = (VideoControl)_player.getControl("VideoControl"); 
     _rc = (RecordControl)_player.getControl("RecordControl");    
     final Field videoField = (Field)_vc.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");    
     _vc.setDisplaySize(Display.getWidth(), Display.getHeight()); 
     add(videoField); 
    } catch (final Exception e) { 
     System.out.println("Exception in VideoScreen constructor"); 
    } 
    addMenuItem(new MenuItem("Start Video Recording", 0, 0){ 
     public void run(){ 
      startRecord(); 
     } 
    }); 
    addMenuItem(new MenuItem("Stop Video Recdording", 0, 0){ 
     public void run(){ 
      stopRecord(); 
     } 
    }); 
    addMenuItem(new MenuItem("Save Video Recording", 0, 0){ 
     public void run(){ 
      commit(); 
      UiApplication.getUiApplication().invokeLater(new Runnable() {        
        public void run() { 
        UiApplication.getUiApplication().popScreen(MyScreen.this); 
        } 
       }); 
     } 
    }); 
} 
} 
관련 문제