问题
In my Blackberry app I've implemented the camera and would like to replace the default shutter sound with my own. I figured I could do this by silencing the default camera sound by using the method enableShutterFeedback(false) then playing my own sound, or playing my sound immediately before the camera is activated.
private void initializeCamera()
{
try
{
// Create a player for the Blackberry's camera
Player player = Manager.createPlayer( "capture://video" );
// Set the player to the REALIZED state (see Player javadoc)
player.realize();
// Grab the video control and set it to the current display
_videoControl = (VideoControl)player.getControl( "VideoControl" );
if (_videoControl != null)
{
// Create the video field as a GUI primitive (as opposed to a
// direct video, which can only be used on platforms with
// LCDUI support.)
_videoField = (Field) _videoControl.initDisplayMode (VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");
_videoControl.setDisplayFullScreen(true);
_videoControl.setVisible(false);
}
cc = (CameraControl)player.getControl("CameraControl");
cc.enableShutterFeedback(false);
// Set the player to the STARTED state (see Player javadoc)
player.start();
}
catch(Exception e)
{
MyApp.errorDialog("ERROR " + e.getClass() + ": " + e.getMessage());
}
}
This results in a Null pointer exception but can't figure out what's causing it, the camera's video doesn't get displayed. If I remove the CameraControl code in bold then the camera's video is shown. Any ideas what I should try to get rid of the shutter sound? I tried VolumeControl in place of CameraControl, same results, null pointer.
回答1:
The CameraControl code gives a NPE because player.getControl
returns null, and it does so because the string param is not correct. Try this one:
CameraControl control = (CameraControl) p.getControl("javax.microedition.amms.control.camera.CameraControl");
来源:https://stackoverflow.com/questions/9657619/j2me-using-javax-microedition-amms-control-camera-cameracontrol-is-it-possibl