Skip to main content

Camera MIDlet is mot working

3 replies [Last post]
prithwi
Offline
Joined: 2008-08-23
Points: 0

Hi,
I have made a camera midlet which is not working with my phone(Nokia 3110c). But it is working well with Sony Ericsson K550i and Nokia N73. I am using NetBeans IDE 6.1 and jdk 1.6. In my phone, vedio screen is opening, but I can't captute the image. I suspect that there is a problem between my phone(3110c) and getSnapshot(). I call the capture() within a thread. Do I need any kind of extra sdk to install in my phone? Or any kind of change in my code? Thanks in advance.

Regards,
Prithwi

//////////
public void capture() {
try {
Form f = new Form("new");
byte[] raw = mVideoControl.getSnapshot(null);
Image image = Image.createImage(raw, 0, raw.length);

f.append(image);
f.addCommand(hi);
f.setCommandListener(this);

mDisplay.setCurrent(f);

mPlayer.close();
mPlayer = null;
mVideoControl = null;
}
catch (Exception me) { }
}
//////////////////////

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sfitzjava
Offline
Joined: 2003-06-15
Points: 0

Need to see your code for setting up the player.
It looks like you used this example from Jonathon:
http://developers.sun.com/mobility/midp/articles/picture/

But this is setup for video capture.

Sometimes the issue is in the order of the calls. But the 3110c should work, and there are no other jars needed for photos, as these have to be included on the device and jsr 135 is supported on that phone.

So it is most likely an ordering of the code, setup of the player, permissions, or for nokia make sure not to have a MIDlet-class, or MIDlet-build in the jar.

-Shawn

prithwi
Offline
Joined: 2008-08-23
Points: 0

Thanks for ur reply. Here is my code.

Source Code:
///////////////////////////////////////
import java.io.IOException;

import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import javax.microedition.midlet.MIDlet;

public class SnapperMIDlet
extends MIDlet
implements CommandListener,Runnable {
private Display mDisplay;

private Form mMainForm;
private ImageItem it = null;

private Command mExitCommand, mCameraCommand;
private Command mBackCommand, mCaptureCommand;
private Command hi;

private Player mPlayer;
private VideoControl mVideoControl;

public SnapperMIDlet() {
mExitCommand = new Command("Exit", Command.EXIT, 0);
mCameraCommand = new Command("Camera", Command.SCREEN, 0);
mBackCommand = new Command("Back", Command.BACK, 0);
mCaptureCommand = new Command("Capture", Command.SCREEN, 0);

hi = new Command("Back", Command.BACK, 0);

mMainForm = new Form("Snapper");
mMainForm.addCommand(mExitCommand);

mMainForm.append("Ready to take pictures.");
mMainForm.addCommand(mCameraCommand);

mMainForm.setCommandListener(this);
}

public void startApp() {
mDisplay = Display.getDisplay(this);

mDisplay.setCurrent(mMainForm);
}

public void pauseApp() {}

public void destroyApp(boolean unconditional) {
}

public void commandAction(Command c, Displayable s) {
if (c.getCommandType() == Command.EXIT) {
destroyApp(true);
notifyDestroyed();
}
else if (c == mCameraCommand)
showCamera();
else if (c == mBackCommand)
mDisplay.setCurrent(mMainForm);
else if (c == mCaptureCommand) {

try
{
Thread t = new Thread(this);
t.start();
}
catch(Exception e)
{}
}
else if(c==hi)
{destroyApp(true);
notifyDestroyed();}
}

public void run()
{ capture(); }
public void showCamera() {
try {
mPlayer = Manager.createPlayer("capture://video");
mPlayer.realize();

mVideoControl = (VideoControl)mPlayer.getControl("VideoControl");

Form form = new Form("Camera form");
Item item = (Item)mVideoControl.initDisplayMode(
GUIControl.USE_GUI_PRIMITIVE, null);
form.append(item);
form.addCommand(mBackCommand);
form.addCommand(mCaptureCommand);
form.setCommandListener(this);
mDisplay.setCurrent(form);

mPlayer.start();
}
catch (Exception ioe) { }
}

public void capture() {
try {

Form f = new Form("new");
byte[] raw = mVideoControl.getSnapshot(null);
Image image = Image.createImage(raw, 0, raw.length);

f.append(image);
f.addCommand(hi);
f.setCommandListener(this);

mDisplay.setCurrent(f);

mPlayer.close();
mPlayer = null;
mVideoControl = null;
}
catch (Exception me) { }
}

}

///////////////////////////////////////////////////////

sfitzjava
Offline
Joined: 2003-06-15
Points: 0

You may need to use the other video method instead of GUIControl.USE_GUI_PRIMITIVE, use the VideoControl.USE_DIRECT_VIDEO method with a canvas component.

Here is some sample code to try.
http://www.roseindia.net/j2me/video-control-midlet.shtml
or
http://developer.motorola.com/docstools/technicalarticles/JSR_135.pdf