在我的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,结果相同,为空指针。

最佳答案

CameraControl代码提供了NPE,因为player.getControl返回null,并且这样做是因为字符串参数不正确。试试这个:

CameraControl control = (CameraControl) p.getControl("javax.microedition.amms.control.camera.CameraControl");

10-01 16:20