Author : Abdul Hye Fahad
Country: Pakistan
Email : abdulhye@gmail.com
Hello All,
My Final year project was related to J2ME Video Streaming, yet very less success but i want to share my experiences here so that no one else gets misguided by reading contradictory statements on forums.
Recording of Video with J2ME. (Record Control)
People! Not all phones have developed J2ME Media API Completely.
Video Recording is not supported in any Sony Ericsson handset as far as i have researched whether its W810i or P900
but Good news ! it is supported in Nokia Phones that Support
SDK S40 3rd Generation Feature Pack 2 and onwards like S60
For example: I have recorded video using E51 of Nokia Cell phone
Following is the code for Video Recording
Filename : CaptureForm.java
Code:/* * CaptureForm.java * * Created on October 1, 2007, 8:43 AM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package myProject; import java.io.ByteArrayOutputStream; import java.io.ByteArrayInputStream; import javax.microedition.lcdui.*; import javax.microedition.media.*; import javax.microedition.media.control.*; public class CaptureForm extends Form implements CommandListener { private final static Command CMD_EXIT = new Command("Exit", Command.EXIT, 1); private final static Command CMD_Capture = new Command ("Capture",Command.OK,1); private final static Command CMD_STOP = new Command ("Stop",Command.OK,1); private final static Command CMD_View = new Command ("View",Command.OK,1); private OLIVS parentMidlet ; private Player myPlayer; private VideoControl videoControl; VolumeControl volumeControl; private VideoCanvas videoCanvas; //RECORDING .... ByteArrayOutputStream output; RecordCamera recording=null; ViewVideo viewvideo=null; //private final static Command CMD_BACK = // new Command("Back", Command.SCREEN, 1); public CaptureForm(String name, OLIVS parent) { super(name); parentMidlet = parent; initComponents(); } public void initComponents() { (new CameraThread()).start(); } public void commandAction(Command c, Displayable d) { if (c == CMD_EXIT) { parentMidlet.destroyApp(true); parentMidlet.notifyDestroyed(); } else if (c==CMD_Capture) { videoCanvas.removeCommand(CMD_Capture); videoCanvas.addCommand(CMD_STOP); recording = new RecordCamera(); recording.start(); } else if (c==CMD_STOP) { videoCanvas.removeCommand(CMD_STOP); videoCanvas.addCommand(CMD_View); videoCanvas.addCommand(CMD_EXIT); if(recording!=null) { recording.StopRecord(); } } else if (c==CMD_View) { if(viewvideo!=null) { viewvideo= new ViewVideo(); viewvideo.start(); } } } private void showCamera() { try { releaseResources(); myPlayer = Manager.createPlayer("capture://video"); myPlayer.realize(); videoControl = (VideoControl)myPlayer.getControl("VideoControl"); videoCanvas = new VideoCanvas(); videoCanvas.initControls(videoControl, myPlayer); videoCanvas.addCommand(CMD_EXIT); videoCanvas.addCommand(CMD_Capture); videoCanvas.setCommandListener(this); parentMidlet.getDisplay().setCurrent(videoCanvas); myPlayer.start(); } catch (Exception e) { e.printStackTrace(); } } public void releaseResources() { try{ if(myPlayer!=null) { myPlayer.stop(); myPlayer.close(); } } catch(Exception e) { } } class ViewVideo extends Thread { public void run() { viewVideo(); } public void viewVideo() { try { releaseResources(); ByteArrayInputStream bis = new ByteArrayInputStream(output.toByteArray()); myPlayer = Manager.createPlayer(bis, "video/3gpp"); myPlayer.realize(); videoControl = (VideoControl)myPlayer.getControl("VideoControl"); volumeControl = (VolumeControl)myPlayer.getControl("VolumeControl"); volumeControl.setLevel(100); if ( videoCanvas != null ) { videoCanvas.initControls(videoControl, myPlayer); parentMidlet.getDisplay().setCurrent(videoCanvas); myPlayer.start(); } } catch (Exception e){ e.printStackTrace(); } } } class CameraThread extends Thread { public void run() { showCamera(); } } class RecordCamera extends Thread { //RECORDING!!!..... RecordControl rc; public void run() { RecordVideo(); } public void RecordVideo() { try{ rc= (RecordControl)myPlayer.getControl("RecordControl"); if(rc==null) { return; } output = new ByteArrayOutputStream(); rc.setRecordStream(output); rc.startRecord(); } catch(Exception e) { e.printStackTrace(); } } public void StopRecord() { try{ if(rc!=null) { rc.stopRecord(); rc.commit(); // writeFile = new FileOutputStream ("c:/MSSEMC/Media files/other/my.3gp"); } } catch(Exception e) { e.printStackTrace(); } } } }
Filename : OLIVS.java (its a midlet)
Code:package myProject; /* * OLIVS.java * * Created on October 1, 2007, 7:45 AM */ import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import myProject.CaptureForm; /** * * @author Abdul Hye Fahad * @version */ public class OLIVS extends MIDlet { private Display display; private CaptureForm capture; public OLIVS() { capture = new CaptureForm("MY Application",this); } public void startApp() { display= Display.getDisplay(this); display.setCurrent(capture); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public Display getDisplay() { return display; } }
Filename : VideoCanvas.java
Code:/* * VideoCanvas.java * * Created on October 1, 2007, 9:14 AM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package myProject; import javax.microedition.lcdui.Canvas; import javax.microedition.lcdui.Graphics; import javax.microedition.media.MediaException; import javax.microedition.media.Player; import javax.microedition.media.control.VideoControl; /** * * @author Abdul Hye Fahad */ public class VideoCanvas extends Canvas { private VideoControl vc = null; private Player plr = null; private boolean RecordingStart; public void initControls(VideoControl videoControl, Player player) { RecordingStart = false; int width =0; int height =0; this.vc = videoControl; this.plr = player; videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this); try { width =getWidth(); height = getHeight(); videoControl.setDisplayLocation(0, 0); //videoControl.setDisplayLocation(4, 4); videoControl.setDisplaySize(width, height ); } catch (MediaException me) { } videoControl.setVisible(true); } public void setRecordingVar(boolean var) { RecordingStart=var; } public void paint(Graphics g) { /* if(vc!=null) { if(!RecordingStart) { int width = vc.getDisplayWidth(); int height = vc.getDisplayWidth(); // Draw a green border around the VideoControl. g.setColor(0x0ff00); g.drawRect(0, 0, width , height); g.fillRect(0,0,width,height); } else if (RecordingStart) { int width = vc.getDisplayWidth(); int height = vc.getDisplayWidth(); // Draw a green border around the VideoControl. g.setColor(0xff000); g.drawRect(0, 0, width , height); g.fillRect(0,0,width,height); } // String s= "Recording"; // char array[]=s.toCharArray(); // // g.drawChars(array,0,9,0,0,0); //g.drawRect(1, 1, width , height ); }*/ } }
********************************************************
is there any Emulator that supports video recording
There is no emulator that supports video recording because it does not connect camera hence, record control will throw exception
but dont worry, Record control wont throw exception when you will run your code in cell phones
*********************************************************
How to Check SDK Support for Cell phone
Go to www.forum.nokia.com
login as a user
> Platforms > Series 40 Platform , Series 60 Platform
and choose Devices ,, this will tell ya that your phone supports which version

Reply With Quote



