Skip to main content

How to integrate MMA with LWUIT

3 replies [Last post]
yt7589
Offline
Joined: 2008-05-06
Points: 0

hi.
I display the capture video from a LWUIT in one of the Demos. It will display the captured video correctly at first. After ten seconds it will return to LWUIT interface. I can start capture video again without any problem. But it will quit again.

I think may be LWUIT repaint the interface periodly without regard to MMA's VideoControl object. So when LWUIT get the access to repaint the screen by competition with VideoControl it will cause the VideoControl to quit.

This is the code I used. Please notice that in order to get the Canvas object VideoControl needs I add a new method getImplementation() to the Display class.

I define the following methods in the Application:
private void releaseResources() {
if (player != null) {
try {
player.stop();
player.close();
} catch (Exception e) {
}
}
}

private void showCamera() {
try {
releaseResources();
player = Manager.createPlayer("capture://video");
player.realize();
videoControl = (VideoControl) player.getControl("VideoControl");

videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, Display.getInstance().getImplementation());
videoControl.setDisplayLocation(2, 2);
videoControl.setDisplaySize(currForm.getWidth() -4, currForm.getHeight() - 4);
videoControl.setVisible(true);
player.start();
contentType = player.getContentType();
} catch (Exception e) {
e.printStackTrace();
}
}

I define a class to start the video capture thread:
class CameraThread extends Thread {
public void run() {
showCamera();
}
}

I use this code to start the video capture thread:
(new CameraThread()).start();

What wrong with my method?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
chenf
Offline
Joined: 2008-04-29
Points: 0

Hi,
To integrate mmapi video check out the com.sun.lwuit.MediaComponent.

Regards,
Chen

pschar
Offline
Joined: 2008-05-30
Points: 0

Chen,

I'd like to follow up on your suggestion. I also have a need to capture camera images using VideoControl.USE_DIRECT_VIDEO. Playing around, I found that I was able to 'mix' LCDUI and LWUIT by switching back and forth (see below). I didn't test this thoroughly, but it appeared to work fine. Do you see any problems with doing this? Based on my (limited) knowledge of how LWTUI is implemented, I would expect this to work ok.

Tom

---

Display.init(midlet);
com.sun.lwuit.Form mainForm = new com.sun.lwuit.Form("Form");
form.show();
.
.
.
// Respond to button press
javax.microedition.lcdui.Canvas captureCanvas = new CaptureCanvas();
Display.getDisplay(midlet).setCurrent(captureCanvas);
.
.
.
// Picture taken, go back to LWUIT form
form.show();

chenf
Offline
Joined: 2008-04-29
Points: 0

Hi Tom,
Your approach should work, the MediaComponent should be used if you would like to create a LWUIT form with media and other Components ( Such as a video player with play, pause, ... buttons)

Regards,
Chen