0

我有一个自定义相机实现,我想在拍摄照片时有自己的声音如何在硬件相机中启用快门声音,我只需要播放我的相机声音而不是默认声音

 private async void TakePhotoButtonTapped(object sender, EventArgs e)
        {

            Android.Hardware.Camera.CameraInfo info = new Android.Hardware.Camera.CameraInfo();
            // mCameraFacing is CameraID.
            Android.Hardware.Camera.GetCameraInfo(mCameraFacing, info);
            if (info.CanDisableShutterSound)
                camera.EnableShutterSound(false);
            else
                camera.EnableShutterSound(true);
            Bitmap image = textureView.Bitmap;
            using (var imageStream = new MemoryStream())
            {
                await image.CompressAsync(Bitmap.CompressFormat.Jpeg, 100, imageStream);
                image.Recycle();
                imageBytes = imageStream.ToArray();
                AddImages(imageBytes);
                Toast.MakeText(Android.App.Application.Context, _languageCache.Translate("Photo Captured"), ToastLength.Short).Show();
            }
            await Task.Delay(300);

        }
4

1 回答 1

0

您可以使用声音设置下面的代码并将其放入您用来拍照的代码中。

我使用系统ShutterClick声音作为参考。你也可以使用你自己的。

  private void SoundSettings()
    {
        MediaActionSound sound = new MediaActionSound();
        AudioManager meng = (AudioManager)Context.GetSystemService(Context.AudioService);
        int volume = meng.GetStreamVolume(Android.Media.Stream.Notification);
        if (volume != 0)
            sound.Play(MediaActionSoundType.ShutterClick);
    }
于 2021-08-27T06:15:50.680 回答