11-21-2009 06:13 PM - last edited on 11-21-2009 06:48 PM
I saw that some people had posted on trying to figure how to use the camera flash back in May. Looking through the API I though I found what was needed, but being new to java and blackberry development, I'm guessing I'm just doing something wrong. Using javax.microedition.amms.control.camera.FlashContro
import java.io.IOException;
import javax.microedition.amms.control.camera.*;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;
public class flashlight extends UiApplication {
public static void main(String[] args) {
flashlight theApp = new flashlight();
theApp.enterEventDispatcher();
}
public flashlight() {
pushScreen(new flashlightScreen());
}
}
final class flashlightScreen extends MainScreen {
public flashlightScreen() {
super();
LabelField title = new LabelField("Flashlight", LabelField.ELLIPSIS
| LabelField.USE_ALL_WIDTH);
setTitle(title);
Player _player = null;
try {
_player = Manager.createPlayer("capture://image");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
title.setText(e.getMessage(), 0, -1);
} catch (MediaException e) {
// TODO Auto-generated catch block
e.printStackTrace();
title.setText(e.getMessage(), 0, -1);
}
if (_player != null) {
FlashControl l = (FlashControl) _player.getControl("javax.microedition.amms.control.camera.FlashControl");
l.setMode(3);
}
}
}
It's obviously not a user friendly program yet, but I'm going for proof of concept first. Any tips as to why this didn't work when I put it on my Storm?
Edit: It's throwing an exception (the MediaException IIRC) with the message Device not supported from createPlayer. Is capture://image wrong?
11-21-2009 07:56 PM
Well, I've made some progress... I think... I don't get any exceptions anymore, but still no light from the flashlight:
import java.io.IOException;
import javax.microedition.amms.control.camera.*;
import javax.microedition.media.Control;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;
public class flashlight extends UiApplication {
static Player _player;
public static void main(String[] args) {
flashlight theApp = new flashlight();
theApp.enterEventDispatcher();
}
public flashlight() {
pushScreen(new flashlightScreen());
}
}
final class flashlightScreen extends MainScreen {
public flashlightScreen() {
super();
LabelField title = new LabelField("Flashlight", LabelField.ELLIPSIS
| LabelField.USE_ALL_WIDTH);
setTitle(title);
Player _player = null;
try {
_player = Manager.createPlayer("capture://video");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
title.setText(e.getMessage(), 0, -1);
} catch (MediaException e) {
// TODO Auto-generated catch block
e.printStackTrace();
title.setText(e.getMessage(), 0, -1);
}
if (_player != null) {
try {
_player.realize();
} catch (MediaException e) {
// TODO Auto-generated catch block
e.printStackTrace();
title.setText(e.getMessage(), 0, -1);
}
Control cs[];
cs = _player.getControls();
FlashControl l = (FlashControl) _player.getControl("javax.microedition.amms.contro l.camera.FlashControl");
l.setMode(FlashControl.FORCE);
try {
_player.start();
} catch (MediaException e) {
// TODO Auto-generated catch block
e.printStackTrace();
title.setText(e.getMessage(), 0, -1);
}
}
}
}
11-22-2009 07:30 PM
Several of us have video-light flashlights on the market, and none of us have yet found a way to activate that light from within a 3rd-party app, be it MIDlet or CLDC. All of the flashlight apps I've seen that use the video light can work in two ways:
1. With light configured off by default in video camera app, user starts the flashlight app, which starts the video camera, and user then has to press spacebar to activate the light. Flashlight app then keeps light from turning off as it normally would.
2. With light configured on by default in video camera app, user starts the flashlight app, which starts the video camera, and the light comes on immediately. Flashlight app then keeps light from turning off as it normally would. When starting the video camera for use as a camera, user has to press spacebar to turn the light off if it's not desired.
I won't post my code, but if you contact Shao either here or on another forum, he seems to have been the 1st guy to get this to work right and would probably share his code with you. He had it up on another forum until someone else who's making a lot of money off a flashlight griped about it, but if there's a copyright involved Shao owns it, he published first.
If you just want a light for your own use without paying for it, ask Shao for a copy of FlashOn.
11-23-2009 05:02 PM - last edited on 11-23-2009 05:03 PM
That's unfortunate that he took it down. You can't own a copyright for software that simply uses an existing API. He, and everyone else, has every right to develop and distribute such software however they please. It's too bad corporate bullies push people around so they can continue to make money off of something that they probably have no claim to. Thanks for the tips! It seems silly to me that such a simple function isn't built into the camera in the first place. It does d**n near everything else. *shrugs*
10-14-2010 03:46 PM
I tried to figure the problem. But the key is at the line.
flashcontrol.setMode(FlashControl.FORCE);
When I execute the getSnapshot --> always show exception??
public String takePicture(){
String imageName;
try {
imageName=createImage(_videoControl.getSnapsh
player.stop();
player.realize();
player.start();
//state5=player.getState();
}
10-16-2011 03:11 AM
Stepless Control Torch R20
Xeccon R20 Stepless Control Torch is a compact stepless control torch developed for hiking, camping, night fishing and other outdoor activities. It features a body made of T7050 durable aircraft-grade aluminum, toughened ultra-clear glass lens with anti-reflective coating and a hard-anodized bezel and tailcap switch. It uses a virtually indestructible power-regulated CREE MC-E LED and Orange peel aluminum reflector to produce a consistently smooth beam.