我有一个 iPhone 应用程序,女巫可以录制视频。问题是方向,它总是纵向的。我需要它来检测设备方向,然后以正确的方向保存视频。
// setup video recording
mRecordingDelegate = new RecordingDelegate();
// setup the input Video part
mCaptureVideoInput = new AVCaptureDeviceInput(AVCaptureDevice.DefaultDeviceWithMediaType(AVMediaType.Video), out mVideoError);
//Audio part
mCaptureAudioInput = new AVCaptureDeviceInput(AVCaptureDevice.DefaultDeviceWithMediaType(AVMediaType.Audio), out mAudioError);
// setup the capture session
mCaptureSession = new AVCaptureSession();
mCaptureSession.SessionPreset = AVCaptureSession.PresetMedium;
mCaptureSession.AddInput(mCaptureVideoInput);
mCaptureSession.AddInput(mCaptureAudioInput);
// setup the output
mCaptureOutput = new AVCaptureMovieFileOutput();
mCaptureOutput.MaxRecordedDuration = MonoTouch.CoreMedia.CMTime.FromSeconds(VideoLength, 1);
//add Output to session
mCaptureSession.AddOutput(mCaptureOutput);
// add preview layer
mPrevLayer = new AVCaptureVideoPreviewLayer(mCaptureSession);
mPrevLayer.Frame = new RectangleF(0, 0, 320, 480);
mPrevLayer.BackgroundColor = UIColor.Clear.CGColor;
mPrevLayer.VideoGravity = "AVLayerVideoGravityResize";
// Show video output
mCaptureSession.CommitConfiguration();
mCaptureSession.StartRunning();
RecordingDelegate.Stopped += delegate {
if(recording)
OnBtnStopRecordingVideo();
};
// add subviews
this.InvokeOnMainThread (delegate
{
this.View.Layer.AddSublayer (mPrevLayer);
});