Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
New Developer
coder0xff
Posts: 13
Registered: 11-21-2009

Trying to make a flashlight

[ Edited ]

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.FlashControl interface:

 

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?

 

Please use plain text.
New Developer
coder0xff
Posts: 13
Registered: 11-21-2009

Re: Trying to make a flashlight

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.control.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);			
			}
		}
	}
}

 

 

Please use plain text.
Developer
mlamagra
Posts: 204
Registered: 07-09-2009

Re: Trying to make a flashlight

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.

 

Please use plain text.
New Developer
coder0xff
Posts: 13
Registered: 11-21-2009

Re: Trying to make a flashlight

[ Edited ]

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*

Please use plain text.
Trusted Contributor
lyon819
Posts: 122
Registered: 08-19-2010
My Carrier: TT

Re: Trying to make a flashlight

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.getSnapshot(_encoding));
          player.stop();
          player.realize();
          player.start();
          //state5=player.getState();
        }

Please use plain text.
New Contributor
xecconlight
Posts: 6
Registered: 10-16-2011
My Carrier: cc3

Re: Trying to make a flashlight

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.

Please use plain text.