当我开始录制视频时,我正在尝试按照苹果的要求播放“哔”声。我通过 SO 和其他来源发现,当您在没有任何配置的情况下进行音频输入时,您无法播放声音。
这是我对配置方法的尝试:
private void SetupAudio()
{
beepSound = AssetBank.GetSystemSoundWav("video_record", "video_beep");
AudioSession.Initialize();
AudioSession.Interrupted += delegate
{
Console.WriteLine("Interrupted handler");
};
AudioSession.Category = AudioSessionCategory.PlayAndRecord;
AudioSession.OverrideCategoryMixWithOthers = true;
NSError err;
AVAudioSession.SharedInstance().SetActive(true, out err);
}
这是我设置录制会话的代码:
public void SetupVideoCaptureSession(AVCaptureDevicePosition position)
{
// Setup devices
foreach (var device in AVCaptureDevice.Devices)
{
if (device.HasMediaType(AVMediaType.Video))
{
if (device.Position == AVCaptureDevicePosition.Front)
{
frontCam = device;
} else if (device.Position == AVCaptureDevicePosition.Back)
{
backCam = device;
}
}
}
// Create capture session
captureSession = new AVCaptureSession();
captureSession.BeginConfiguration();
captureSession.SessionPreset = AVCaptureSession.Preset640x480;
// Create capture device
switch (position)
{
case AVCaptureDevicePosition.Back:
videoDevice = backCam;
break;
case AVCaptureDevicePosition.Front:
videoDevice = frontCam;
break;
}
if (null == videoDevice)
{
using (var alert = new UIAlertView { Message = "No camera detected!" })
{
alert.AddButton("Okay!");
alert.Show();
}
return;
}
audioDevice = AVCaptureDevice.DefaultDeviceWithMediaType(AVMediaType.Audio);
// Create capture device input
NSError videoError, audioError;
videoDeviceInput = new AVCaptureDeviceInput(videoDevice, out videoError);
audioDeviceInput = new AVCaptureDeviceInput(audioDevice, out audioError);
captureSession.AddInput(videoDeviceInput);
captureSession.AddInput(audioDeviceInput);
// Create capture device output
videoOutput = new AVCaptureMovieFileOutput();
videoOutput.MaxRecordedDuration = new CMTime(10, 1);
captureSession.AddOutput(videoOutput);
if (null != previewLayer)
previewLayer.RemoveFromSuperLayer();
// Create preview layer
previewLayer = AVCaptureVideoPreviewLayer.FromSession(captureSession);
previewLayer.Orientation = AVCaptureVideoOrientation.Portrait;
previewLayer.VideoGravity = "AVLayerVideoGravityResizeAspectFill";
previewLayer.Frame = new RectangleF(new PointF(), ScreenSize);
this.ParentScrollView.Layer.InsertSublayer(previewLayer, 0);
// Start capture session
SetupAudio();
captureSession.CommitConfiguration();
captureSession.StartRunning();
}
无论我尝试什么,在开始捕获会话后我都无法播放声音。有人在 MonoTouch 中解决了这个问题吗?