×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    6

    Record Video using RecordControl J2ME

    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

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    46

    Re: Record Video using RecordControl J2ME

    Hi there,
    I am also doing video recording on my Nokia 6233. This is very true that any emulator till now does not support the RecordControl for the video and when you try to get it on emulator it returns as null.
    But it is running peacefully on device. The major problem I am facing is that it gets STOP event from system when you reach at some size level like Nokia 6233 support 99KB, Nokia 6500c Support 112KB.
    Are you facing the same problem too. if yes then have you solved it. and if yes then HOW
    I did recording on the Stream as well as File but both are having the same limit.

    Please help me if you have sorted out this problem.
    Thanks
    Regards,

    Vishal

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    7

    Re: Record Video using RecordControl J2ME

    Hey,

    i just stumbled upon your thread. Be aware that Sony-Ericsson is using a special locator string for recording Videos:

    Code:
    player = Manager.createPlayer("capture://audio_video");
    Reference:

    https://developer.sonyericsson.com/docs/DOC-704

    Anyway, this does NOT work with my SE W890i. It is just able to record sound (and the application just asks for allowing sound recording). There is no exception and no null pointer return of Player, RecordControl, VideoControl and so on.

    So, if anyone has experiences, share them please...

    Ben

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4

    Thumbs up Re: Record Video using RecordControl J2ME

    Quote Originally Posted by ben-efiz View Post
    Hey,

    i just stumbled upon your thread. Be aware that Sony-Ericsson is using a special locator string for recording Videos:

    Code:
    player = Manager.createPlayer("capture://audio_video");
    Reference:

    https://developer.sonyericsson.com/docs/DOC-704

    Anyway, this does NOT work with my SE W890i. It is just able to record sound (and the application just asks for allowing sound recording). There is no exception and no null pointer return of Player, RecordControl, VideoControl and so on.

    So, if anyone has experiences, share them please...

    Ben

    Thanks a lot ben-efiz!! I had almost lost hope of recording video wen i read this post of urs. Worked like magic on my Sony Ericsson w610i! Thanks a lot for this tip!!
    Last edited by radioactivet; 2009-08-02 at 12:47. Reason: Had to mention the model name and number of my cellphone.

  5. #5
    Registered User
    Join Date
    Aug 2011
    Posts
    1

    Re: Record Video using RecordControl J2ME

    your code samples and explanations have help me alot
    thanks ...

Similar Threads

  1. Maximum Record size problem in j2me
    By harshalpatil in forum Mobile Java General
    Replies: 4
    Last Post: 2007-05-30, 03:16
  2. screensaver appears over J2ME video
    By redlex in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2006-12-02, 09:52
  3. video capture using j2me
    By shalini.mishra in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2006-11-15, 17:26
  4. record video in series 60 (3650) phones
    By chen_li in forum Symbian
    Replies: 1
    Last Post: 2003-07-10, 13:10
  5. 3650 Video Recorder - Won't Record
    By johnrid11 in forum General Development Questions
    Replies: 0
    Last Post: 2003-05-13, 00:11

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •