【问题标题】:How to EnableShutterSound while taking picture in android xamarin如何在android xamarin中拍照时启用ShutterSound
【发布时间】:2021-10-26 12:46:30
【问题描述】:

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

 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);

        }

【问题讨论】:

    标签: xamarin.android android-camera shutter


    【解决方案1】:

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

    我使用系统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);
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多