×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Apr 2011
    Location
    Ha Noi, Viet Nam
    Posts
    5

    Smile RecordControl returns null while trying to record Video

    hi everyone!
    can any body help me in my problem.I m trying record Video but RecordControl returns null. I don't know why? I use SDK 3.0 platform
    I downloaded this code from network.
    Thanks

    package example;

    import java.io.OutputStream;
    import java.util.Date;

    import javax.microedition.io.Connector;
    import javax.microedition.io.file.FileConnection;
    import javax.microedition.lcdui.Alert;
    import javax.microedition.lcdui.AlertType;
    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Graphics;
    import javax.microedition.media.Manager;
    import javax.microedition.media.Player;
    import javax.microedition.media.PlayerListener;
    import javax.microedition.media.control.RecordControl;
    import javax.microedition.media.control.VideoControl;

    public class VideoCanvas extends Canvas implements PlayerListener, CommandListener {

    private VideoRecordMIDlet midlet = null;
    private Command start = new Command("Start",Command.OK,0);
    private Command stop = new Command("Stop",Command.OK,1);
    private Command exit = new Command("Exit",Command.BACK,0);
    private Command play = new Command("Play",Command.OK,2);
    private String status = "Not initialized";
    private Player player = null;
    private VideoControl control = null;
    private RecordControl record = null;
    private boolean recording = false;
    private FileConnection conn = null;
    private OutputStream stream = null;
    private String PATH = System.getProperty("fileconn.dir.videos");
    private String videoPath = null;

    /**
    * Constructor
    *
    * @param midlet
    */

    public VideoCanvas(VideoRecordMIDlet midlet) {
    System.out.println(PATH);
    this.midlet = midlet;
    addCommand(play);
    addCommand(start);
    addCommand(stop);
    addCommand(exit);
    setCommandListener(this);
    }

    public void commandAction(Command c, Displayable arg1) {
    if(c == start) {
    recording = true;
    startRecording();
    }
    else if(c == stop) {
    stop();
    recording = false;
    }
    else if(c == play) {
    recording = false;
    repaint();
    startPlaying();
    }
    else if(c == exit) {
    midlet.notifyDestroyed();
    }
    }

    /**
    * Paint
    */

    protected void paint(Graphics g) {
    g.setColor(0,0,0);
    g.fillRect(0,0,getWidth(),getHeight());
    }

    public void startRecording() {
    videoPath = PATH + getFileName();
    System.err.println(videoPath);
    try {
    player = Manager.createPlayer("capture://video");
    player.addPlayerListener(this);
    player.realize();

    //setup recording
    record = (RecordControl)player.getControl("RecordControl");
    record.setRecordSizeLimit(300000);
    conn = (FileConnection)Connector.open(videoPath,Connector.READ_WRITE);
    if(!conn.exists()) conn.create();
    stream = conn.openOutputStream();
    record.setRecordStream(stream);

    // Grab the video control and set it to the current display.
    control = (VideoControl)player.getControl("VideoControl");
    if (control != null) {
    control.initDisplayMode(VideoControl.USE_DIRECT_VIDEO,this);
    control.setDisplaySize(getWidth(),getHeight());
    control.setVisible(true);
    }

    player.start();
    record.startRecord();
    }
    catch(Exception e) {
    Alert erro = new Alert("Erro",e.toString(),null,AlertType.ERROR);
    Display.getDisplay(midlet).setCurrent(erro);
    e.printStackTrace();
    }
    }

    /**
    * Start
    *
    */

    public void startPlaying() {
    try {
    player = Manager.createPlayer(videoPath);
    player.addPlayerListener(this);
    player.realize();

    // Grab the video control and set it to the current display.
    control = (VideoControl)player.getControl("VideoControl");
    if (control != null) {
    control.initDisplayMode(VideoControl.USE_DIRECT_VIDEO,this);
    control.setDisplaySize(176,144);
    control.setDisplayLocation((getWidth() - control.getDisplayWidth()) / 2,(getHeight() - control.getDisplayHeight()) / 2);
    control.setVisible(true);
    }

    player.start();
    }
    catch(Exception e) {
    Alert erro = new Alert("Erro",e.getMessage(),null,AlertType.ERROR);
    Display.getDisplay(midlet).setCurrent(erro);
    e.printStackTrace();
    }
    }

    public void stop() {
    if(player != null) {
    try {
    if(recording) {
    record.stopRecord();
    record.commit();
    stream.close();
    }
    player.stop();
    player.deallocate();
    player.close();
    player = null;
    if(recording) {
    Alert alert = new Alert("Message","Recorded in " + videoPath,null,AlertType.INFO);
    Display.getDisplay(midlet).setCurrent(alert,this);
    stream = null;
    }

    if(conn != null)
    conn.close();
    }
    catch(Exception e) {

    }
    }
    }

    public void playerUpdate(Player p, String s, Object o) {

    if(p.getState() == Player.STARTED) {
    status = control.getDisplayHeight() + "=" + control.getDisplayWidth();
    setTitle(status);
    }

    }

    private String getFileName() {
    Date d = new Date();
    String retValue = d.getTime() + "_rec.3gp";
    return retValue;
    }

    }
    Last edited by babylike89; 2011-04-29 at 16:09.

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: RecordControl returns null while trying to record Video

    Welcome to Forum Nokia!

    What, exactly, returns null?

    What are you running this code on? Remember that the emulator might support video capture...

    Graham.

  3. #3
    Registered User
    Join Date
    Apr 2011
    Location
    Ha Noi, Viet Nam
    Posts
    5

    Re: RecordControl returns null while trying to record Video

    Quote Originally Posted by grahamhughes View Post
    Welcome to Forum Nokia!

    What, exactly, returns null?

    What are you running this code on? Remember that the emulator might support video capture...

    Graham.
    I m trying this code but it notifies an error : "java.lang.NullPointerException: 0". haizz!
    I think Jave ME SDK 3.0 to support video capture.
    I can copy link for you that I downloaded this code at there . this is link:
    http://wiki.forum.nokia.com/images/4...eoRecorder.zip
    Can you examine it for me?
    My name is Ngoc. I'm from Viet Nam. Nice to meet you!
    Ngocnt

  4. #4
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: RecordControl returns null while trying to record Video

    Hello, Ngoc! Nice to meet you too!

    You can use the JME SDK 3 to develop apps with video capture. But the emulator emulates a phone with no camera, so when you run your app, it will fail.

    Do you have a real phone you could run this on?

    Graham.

  5. #5
    Registered User
    Join Date
    Apr 2011
    Location
    Ha Noi, Viet Nam
    Posts
    5

    Re: RecordControl returns null while trying to record Video

    yes, i selected a phone with camera to emulate. but it's the same as before. did you test it?
    Ngocnt

  6. #6
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: RecordControl returns null while trying to record Video

    Did you try a real phone? Not the emulator. You will not be able to run this on the emulator.

    Graham.

  7. #7
    Registered User
    Join Date
    Apr 2011
    Location
    Ha Noi, Viet Nam
    Posts
    5

    Re: RecordControl returns null while trying to record Video

    Quote Originally Posted by grahamhughes View Post
    Did you try a real phone? Not the emulator. You will not be able to run this on the emulator.

    Graham.
    Thank you so much. It run well.
    ngocnt

Similar Threads

  1. Record Video using RecordControl J2ME
    By abdulhye in forum Mobile Java Media (Graphics & Sounds)
    Replies: 4
    Last Post: 2011-08-25, 13:40
  2. Replies: 9
    Last Post: 2010-08-18, 09:41
  3. Replies: 5
    Last Post: 2010-01-20, 18:51
  4. Replies: 14
    Last Post: 2009-09-12, 11:42
  5. Save Failed:null in carbide.c++ express while trying to create aifdef
    By razas in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 5
    Last Post: 2006-05-04, 14:14

Posting Permissions

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