Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class VideoRecordingScreen extends MainScreen
- {
- MenuItem stop,play;
- Player player;
- VideoControl videoControl;
- RecordControl recordControl;
- ByteArrayOutputStream oStream;
- ByteArrayInputStream istream;
- Field videoField;
- String encodingFormat;
- byte data[];
- FileConnection fileConn;
- static String PATH;
- boolean save=false;
- public VideoRecordingScreen(String encodingFormat)
- {
- this.encodingFormat=encodingFormat;
- createGUI();
- startVideoRecording();
- }
- private void createGUI()
- {
- stop=new MenuItem("Stop Video",10,100)
- {
- public void run()
- {
- synchronized (UiApplication.getEventLock())
- {
- stopVideoRecording();
- }
- }
- };
- addMenuItem(stop);
- }
- private void startVideoRecording()
- {
- try
- {
- save=true;
- player = Manager.createPlayer("capture://video?"+encodingFormat);
- player.start();
- videoControl = (VideoControl) player.getControl( "VideoControl" );
- recordControl = (RecordControl) player.getControl("RecordControl");
- videoField=(Field)videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");
- add(videoField);
- videoControl.setVisible(true);
- oStream = new ByteArrayOutputStream();
- recordControl.setRecordStream(oStream);
- recordControl.startRecord();
- }
- catch (final Exception e)
- {
- UiApplication.getUiApplication().invokeAndWait(new Runnable()
- {
- public void run()
- {
- Dialog.inform(e.toString());
- }
- });
- }
- }
- private void stopVideoRecording()
- {
- try
- {
- // data=new byte[(int)oStream.size()];
- data=oStream.toByteArray();
- videoControl.setVisible(false);
- recordControl.stopRecord();
- oStream.close();
- player.close();
- long dateinMill=System.currentTimeMillis();
- Date d=new Date(dateinMill);
- SimpleDateFormat formater=new SimpleDateFormat("dd-MM-yyyy-H-m-s"); //Because I want to save the file according to the date and time;
- String str=formater.format(d);
- if(SdcardTest.SdcardAvailabulity())
- PATH="file:///SDCard/BlackBerry/videos/vid"+str+".3gp";
- else
- PATH="file:///store/home/user/videos/vid"+str+".3gp";
- fileConn=(FileConnection) Connector.open(PATH);
- if(!fileConn.exists())
- fileConn.create();
- OutputStream outStream=fileConn.openOutputStream();
- outStream.write(oStream.toByteArray());
- outStream.close();
- fileConn.close();
- UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
- UiApplication.getUiApplication().pushScreen(new PlayVideoScreen(PATH,encodingFormat));
- }
- catch (final Exception e)
- {
- UiApplication.getUiApplication().invokeAndWait(new Runnable()
- {
- public void run()
- {
- Dialog.inform(e.toString());
- }
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement