Hello, simply make use of the code below in your Midlet class:
Code:
import java.io.IOException;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.media.control.VideoControl;
public class Video extends MIDlet implements CommandListener {
private Display dis;
private Form frm;
private Command exit,back,capture,camera;
private Player plr;
private VideoControl vControl;
private Video vid;
public Video() {
exit = new Command("Exit", Command.EXIT, 0);
camera = new Command("Camera", Command.SCREEN, 0);
back = new Command("Back", Command.BACK, 0);
capture = new Command("Capture", Command.SCREEN, 0);
frm = new Form("Capture ");
frm.addCommand(camera);
frm.setCommandListener(this);
}
public void start() {
dis = Display.getDisplay(this);
dis.setCurrent(frm);
}
public void pauseApp() {}
public void remove(boolean unconditional) {}
public void commandAction(Command c, Displayable s) {
if (c == exit) {
remove(true);
notifyDestroyed();
} else if (c == camera) {
showCamera();
} else if (c == back)
dis.setCurrent(frm);
else if (c == capture) {
vid = new Video(this);
vid.start();
}
}
public void showCamera() {
try {
plr = Manager.createPlayer("capture://vid");
plr.realize();
vControl = (VideoControl)plr.getControl("VideoControl");
Canvas canvas = new VideoCanvas(this, vControl);
canvas.addCommand(back);
canvas.addCommand(capture);
canvas.setCommandListener(this);
dis.setCurrent(canvas);
plr.start();
} catch (IOException ioe) {} catch (MediaException me) {}
}
class Video extends Thread {
Video midlet;
public Video(Video midlet) {
this.midlet = midlet;
}
public void run() {
captureVideo();
}
public void captureVideo() {
try {
byte[] bt = vControl.getSnapshot(null);
Image pic = Image.createImage(bt, 0, bt.length);
frm.append(pic);
dis.setCurrent(frm);
plr.close();
plr = null;
vControl = null;
} catch (MediaException me) { }
}
};
}
And the code below in your Video Canvas subclass:
Code:
import javax.microedition.lcdui.*;
import javax.microedition.edia.MediaException;
import javax.microedition.edia.control.VideoControl;
public class vCanvas extends Canvas
{
private VideoMIDlet mdt;
public vCanvas(VideoMIDlet mdt, VideoControl control)
{
int wdth = getWidth();
int hgth = getHeight();
this.mdt = mdt;
control.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this);
try
{
control.setDisplayLocation(2, 2);
control.setDisplaySize(wdth - 4, hgth - 4);
}
catch (MediaException e)
{}
control.setVisible(true);
}
public void paint(Graphics g) {
int wdth = getWidth();
int hgth = getHeight();
g.setColor(0x00ff00);
g.drawRect(0, 0, wdth - 1, hgth - 1);
g.drawRect(1, 1, wdth - 3, hgth - 3);
}
}
This code had solved my same problem. So, you need to use it.
Bookmarks