This is the following code that we've tried to implent which records video after breaks. We have to transmit these video parts through WLAN using our N93. But the big problem is that the code, when deployed for the N93 has the following Problems:

The first video is recorded. All consequent videos recorded after tat will contain only audio and no Video!!!!

I'm uploading the code here so tat any mistakes/corrections can be found.Please do inform, as this is vital to our completion of our final Year project.

This is the Camera Midlet Code:

ProCam.java:

import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.VideoControl;
import javax.microedition.io.file.*;
import javax.microedition.io.*;
import javax.microedition.media.control.RecordControl;

public class ProCam extends MIDlet implements CommandListener, ItemStateListener
{

private Player player;
private VideoControl vcctrl;
private ByteArrayOutputStream output = new ByteArrayOutputStream();
private int n=0;

private Command exitCmd = new Command("Exit",Command.EXIT,1);
private Command zoomCmd = new Command("zoom",Command.ITEM,1);
private Command backCmd = new Command("Back",Command.BACK,3);
private Command saveCmd = new Command("Save",Command.ITEM,3);
private Command startCmd= new Command("start",Command.ITEM,3);
private Command stopCmd= new Command("stop",Command.ITEM,3);
private Command sendCmd=new Command("Send",Command.ITEM,3);

private final Command shutter = new Command("Capture",Command.ITEM,2);


private Display disp;
private Form cForm;
private Form sForm;
private Form zoomModesForm;
private Item vitem;
private ChoiceGroup zoomOptModes;
private ChoiceGroup zoomDigModes;
private String zoomOptSupportedModes[];
private int zoomOptModesInt[];
private String zoomDigSupportedModes[];
private int zoomDigModesInt[];
private TextBox abc=null;
private byte [] snap ;
private byte [] snap1 ;
private String str = "hello";

private RecordControl rc;

public ProCam() throws IOException, InterruptedException
{

cForm=new Form("Camera");
disp=Display.getDisplay(this);
disp.setCurrent(cForm);
cForm.addCommand(exitCmd);
cForm.addCommand(shutter);
cForm.addCommand(startCmd);
cForm.addCommand(stopCmd);
cForm.addCommand(sendCmd);
cForm.setCommandListener(this);


try
{

player=Manager.createPlayer("capture://video");
player.prefetch();
rc = (RecordControl)player.getControl("RecordControl");
//cForm.append(rc.getContentType());

vcctrl = (VideoControl)player.getControl("VideoControl");
/*rc.setRecordLocation("file:///E:/Images/au.mpeg");
rc.startRecord();
Thread.currentThread().sleep(5000);
rc.stopRecord();
rc.commit();*/

if(vcctrl!=null)
{
vitem=(Item)vcctrl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE,null );
vcctrl.setDisplayFullScreen(true);
cForm.append(vitem);

}else{
System.out.println("Cant create");
return;
}



}
catch(MediaException me){
me.printStackTrace();
}
catch (IOException ioe) {
ioe.printStackTrace();}
}
protected void startApp() throws MIDletStateChangeException {
try{
player.start();


}catch(MediaException me){
me.printStackTrace();

}
}

protected void pauseApp() {
throw new UnsupportedOperationException("Not supported yet.");
}

public void destroyApp(boolean unconditional) {
player.close();
notifyDestroyed();
}


public void commandAction(Command c, Displayable d) {
if(c==exitCmd){
destroyApp(false);
}
else if(c == startCmd){

System.out.println("start");
Recorder rec = new Recorder(rc,0);
rec.start();

System.out.println("end");





}
else if(c==backCmd)
{
cForm.deleteAll();
cForm.append(vitem);
cForm.removeCommand(backCmd);
cForm.removeCommand(saveCmd);
cForm.addCommand(shutter);
cForm.addCommand(exitCmd);
cForm.addCommand(sendCmd);
}
else if(c==sendCmd)
{
try{
String ss=snap.toString();
Sender sen=new Sender(ss.getBytes());
sen.start();

}
catch (Exception me) {
System.err.println(me);
}

}
else if(c==saveCmd)
{
try
{
FileConnection fil=(FileConnection)Connector.open("file:///SDCard/Images/gv.jpg");
if (!fil.exists())
fil.create();


OutputStream op= fil.openOutputStream();
op.write(snap);


}catch(IOException ioe){
ioe.printStackTrace();
}
try
{
FileConnection fil1=(FileConnection)Connector.open("file:///SDCard/Images/gv.jpg");
if (fil1.exists())
{
InputStream ip= fil1.openInputStream();
ip.read(snap1);
Image im1= Image.createImage(snap1, 0, snap1.length);
cForm.deleteAll();
cForm.append(im1);
cForm.addCommand(backCmd);
cForm.removeCommand(saveCmd);
}
}catch(IOException ie){
ie.printStackTrace();
}


}
else{
try {
snap = vcctrl.getSnapshot("width=240&height=220");
cForm.append("pic taken");
Image im = Image.createImage(snap, 0, snap.length);
cForm.deleteAll();
cForm.removeCommand(exitCmd);
cForm.removeCommand(shutter);
cForm.append(im);
cForm.addCommand(backCmd);
cForm.addCommand(saveCmd);

} catch (MediaException me) {
System.err.println(me);
}

}

}
public void itemStateChanged(Item arg0) {
throw new UnsupportedOperationException("Not supported yet.");
}

}


Recorder.java: For recording video:


import java.io.*;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.media.*;
import javax.microedition.media.control.RecordControl;


public class Recorder extends Thread {

private RecordControl rc;
public byte [] by;
private int n;
private ByteArrayOutputStream output = new ByteArrayOutputStream();
public Recorder(RecordControl rc,int n)
{
this.rc=rc;
this.n=n;

}


public void run()
{
for(int i=0;i<5;i++)
{
try
{
if(rc==null)
{
System.out.println("error");
System.exit(1);
}


rc.setRecordStream(output);
rc.startRecord();
Thread.sleep(4000);
rc.stopRecord();
rc.commit();
by = output.toByteArray();
output.flush();
output.reset();

{
String ns=Integer.toString(++n);
FileConnection fil=(FileConnection)Connector.open("file:///C:/Data/Images/gv"+ns+".3gp");
if (!fil.exists())
fil.create();

OutputStream op= fil.openOutputStream();
op.write(by);
op.flush();
op.close();
fil.close();

}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

}

Sender.java: For Transmission

import java.io.*;
import java.lang.Thread;
import javax.microedition.io.*;

public class Sender extends Thread {
private DatagramConnection dc;

private byte[] bytes;
public Sender(byte[] b)
{
bytes=b;
}
public void run()
{
try
{
System.out.println("waiting");
dc = (DatagramConnection) Connector.open("datagram://192.168.9.8:5555");
System.out.println("connected");
Datagram dg = null;
dg = dc.newDatagram(bytes, bytes.length);
dc.send(dg);
}
catch (IOException ex) {
ex.printStackTrace();
}
catch (Exception ioe) {
ioe.printStackTrace();
}
}
}