Advertisement
alishaik786

VideoRecordingScreen

Oct 11th, 2011
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. public class VideoRecordingScreen extends MainScreen
  2. {
  3. MenuItem stop,play;
  4.  
  5. Player player;
  6. VideoControl videoControl;
  7. RecordControl recordControl;
  8. ByteArrayOutputStream oStream;
  9. ByteArrayInputStream istream;
  10. Field videoField;
  11.  
  12. String encodingFormat;
  13. byte data[];
  14. FileConnection fileConn;
  15. static String PATH;
  16. boolean save=false;
  17. public VideoRecordingScreen(String encodingFormat)
  18. {
  19. this.encodingFormat=encodingFormat;
  20. createGUI();
  21. startVideoRecording();
  22. }
  23. private void createGUI()
  24. {
  25. stop=new MenuItem("Stop Video",10,100)
  26. {
  27. public void run()
  28. {
  29. synchronized (UiApplication.getEventLock())
  30. {
  31. stopVideoRecording();
  32. }
  33. }
  34. };
  35. addMenuItem(stop);
  36. }
  37.  
  38. private void startVideoRecording()
  39. {
  40. try
  41. {
  42. save=true;
  43.  
  44. player = Manager.createPlayer("capture://video?"+encodingFormat);
  45. player.start();
  46. videoControl = (VideoControl) player.getControl( "VideoControl" );
  47. recordControl = (RecordControl) player.getControl("RecordControl");
  48. videoField=(Field)videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");
  49. add(videoField);
  50. videoControl.setVisible(true);
  51. oStream = new ByteArrayOutputStream();
  52. recordControl.setRecordStream(oStream);
  53. recordControl.startRecord();
  54. }
  55. catch (final Exception e)
  56. {
  57. UiApplication.getUiApplication().invokeAndWait(new Runnable()
  58. {
  59. public void run()
  60. {
  61. Dialog.inform(e.toString());
  62. }
  63. });
  64. }
  65. }
  66.  
  67. private void stopVideoRecording()
  68. {
  69. try
  70. {
  71. // data=new byte[(int)oStream.size()];
  72. data=oStream.toByteArray();
  73. videoControl.setVisible(false);
  74. recordControl.stopRecord();
  75. oStream.close();
  76. player.close();
  77.  
  78. long dateinMill=System.currentTimeMillis();
  79. Date d=new Date(dateinMill);
  80. SimpleDateFormat formater=new SimpleDateFormat("dd-MM-yyyy-H-m-s"); //Because I want to save the file according to the date and time;
  81. String str=formater.format(d);
  82.  
  83. if(SdcardTest.SdcardAvailabulity())
  84. PATH="file:///SDCard/BlackBerry/videos/vid"+str+".3gp";
  85. else
  86. PATH="file:///store/home/user/videos/vid"+str+".3gp";
  87.  
  88. fileConn=(FileConnection) Connector.open(PATH);
  89. if(!fileConn.exists())
  90. fileConn.create();
  91. OutputStream outStream=fileConn.openOutputStream();
  92. outStream.write(oStream.toByteArray());
  93. outStream.close();
  94. fileConn.close();
  95. UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
  96. UiApplication.getUiApplication().pushScreen(new PlayVideoScreen(PATH,encodingFormat));
  97. }
  98. catch (final Exception e)
  99. {
  100. UiApplication.getUiApplication().invokeAndWait(new Runnable()
  101. {
  102. public void run()
  103. {
  104. Dialog.inform(e.toString());
  105. }
  106. });
  107. }
  108. }
  109. }
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement