简体   繁体   English

Android Camera.takePicture-可以禁用快门音和预览表面吗?

[英]Android Camera.takePicture - Possible to disable shutter sound and preview surface?

I am working on an app that will allow a user to take quick click and forget snapshots. 我正在开发一款允许用户快速单击并忘记快照的应用程序。 Most of the app is done except for the camera working that way I would like. 除了我想要的相机工作方式外,大多数应用程序都已完成。 Right now I have the camera working but I can't seem to find a way to disable the shutter sound and I cant find a way to disable displaying the preview. 目前,我正在使用相机,但似乎找不到禁用快门声的方法,也找不到禁用显示预览的方法。 I was able to cover the preview up with a control but I would rather just not have it displayed if possible. 我能够使用控件来覆盖预览,但我宁愿不显示它(如果可能)。

To sum things up, these are the items that I would like to disable while utilizing the built in Camera controls. 综上所述,这些是我在使用内置Camera控件时要禁用的项目。

  1. Shutter sound 快门音
  2. Camera screen display 相机屏幕显示
  3. Image preview onPictureTaken 在PictureTaken上预览图像

Does anyone know of a resource that could point me in the right direction, I would greatly appreciate it. 有谁知道一种资源可以指出我正确的方向,我将不胜感激。 I have been following CommonsWare's example from this sample fairly closely. 我一直在密切关注此示例中的 CommonsWare示例。

Thank you. 谢谢。

This is actually a property in the build.prop of a phone. 这实际上是电话的build.prop中的属性。 I'm unsure if its possible to change this. 我不确定是否可以更改此设置。 Unless you completely override it and use your own camera code. 除非您完全覆盖它并使用自己的相机代码。 Using what you can that is available in the SDK. 使用您可以在SDK中提供的功能。

Take a look at this: 看看这个:

CameraService.cpp . CameraService.cpp . .

CameraService::Client::Client(const sp<CameraService>& cameraService,
        const sp<ICameraClient>& cameraClient,
        const sp<CameraHardwareInterface>& hardware,
        int cameraId, int cameraFacing, int clientPid) {
        mPreviewCallbackFlag = FRAME_CALLBACK_FLAG_NOOP;
            mOrientation = getOrientation(0, mCameraFacing == CAMERA_FACING_FRONT);
            mOrientationChanged = false;
            cameraService->setCameraBusy(cameraId);
            cameraService->loadSound();
            LOG1("Client::Client X (pid %d)", callingPid)
    }

    void CameraService::loadSound() {
        Mutex::Autolock lock(mSoundLock);
        LOG1("CameraService::loadSound ref=%d", mSoundRef);
        if (mSoundRef++) return;

        mSoundPlayer[SOUND_SHUTTER] = newMediaPlayer("/system/media/audio/ui/camera_click.ogg");
        mSoundPlayer[SOUND_RECORDING] = newMediaPlayer("/system/media/audio/ui/VideoRecord.ogg");
    }

As can be noted, the click sound is started without your interaction. 可以注意到,点击声是在没有您进行交互的情况下开始的。

This is the service used in the Gingerbread Source code. 这是Gingerbread源代码中使用的服务。

The reason they DON'T allow this is because it is illegal is some countries. 他们不允许 ,这是因为这是违法的原因是一些国家。 Only way to achieve what you want is to have a custom ROM. 实现所需功能的唯一方法是拥有自定义ROM。

Update 更新

If what being said here: http://androidforums.com/t-mobile-g1/6371-camera-shutter-sound-effect-off.html 如果在这里说了什么: http : //androidforums.com/t-mobile-g1/6371-camera-shutter-sound-effect-off.html

still applies, then you could write a timer that turns off the sound (Silent Mode) for a couple of seconds and then turn it back on each time you take a picture. 仍然适用,那么您可以编写一个计时器来关闭声音(静音模式)几秒钟,然后在每次拍摄时将其重新打开。

You may use the data from the preview callback using a function to save it at a picture on some type of trigger such as a button, using onclick listener. 您可以使用一个函数使用预览回调中的数据,使用onclick侦听器将其保存在某些类型的触发器(例如按钮)上的图片上。 you could compress the image to jpeg or png. 您可以将图像压缩为jpeg或png。 In this way, there no shutterCallback to be implemented. 这样,就无需实现shutterCallback。 and therefore you can play any sound you want or none when taking a picture. 因此,拍摄照片时,您可以播放任何想要的声音,也可以不播放。

You can effectively hide the preview surface by giving it dimensions of 1p in the xml file (I found an example the said 0p but for some reason that was giving me errors). 您可以通过在xml文件中为其指定1p的尺寸来有效地隐藏预览表面(我找到了一个示例,该示例为0p,但由于某些原因导致出现错误)。

It may be illegal to have a silent shutter in some places, but it doesn't appear that the US is such a place, as my HTC One gives me an option to silence it, and in fact, since Android 4.2 you can do this: 在某些地方使用静音快门可能是非法的,但在美国似乎没有这样的地方,因为我的HTC One可以让我选择使其静音,事实上,由于Android 4.2,您可以这样做:

Camera.CameraInfo info=new Camera.CameraInfo();
if (info.canDisableShutterSound) {
    camera.enableShutterSound(false);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM