在我的Blackberry应用程序中,我实现了相机,并希望用我自己的快门声音替换默认的快门声音。我想我可以通过使用方法enableShutterFeedback(false)然后播放我自己的声音来静音默认的相机声音,或者在激活相机之前立即播放我的声音。
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());
}
}
这导致Null指针异常,但无法弄清楚导致它的原因,相机的视频无法显示。如果我以粗体移除CameraControl代码,则会显示相机的视频。有什么想法我应该试图摆脱快门声音?我尝试使用VolumeControl代替CameraControl,结果相同,空指针。
答案 0 :(得分:5)
CameraControl代码给出一个NPE,因为player.getControl
返回null,并且它是这样做的,因为字符串参数不正确。试试这个:
CameraControl control = (CameraControl) p.getControl("javax.microedition.amms.control.camera.CameraControl");