【问题标题】:Video orientation iPhone视频方向 iPhone
【发布时间】:2012-08-21 12:01:10
【问题描述】:

我有一个 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);
});

【问题讨论】:

    标签: iphone video xamarin.ios orientation video-capture


    【解决方案1】:

    1.基础知识

    在深入了解细节之前,让我们先回顾一下界面方向更改的工作原理以及您应该如何应对它们。首先,如果您希望视图自动旋转,您需要覆盖方法 shouldAutorotateToInterfaceOrientation: 并返回 YES。如果您只想在特定条件下允许自动旋转,您也可以在此方法中对该条件进行测试。

    这几乎是允许自动旋转所需做的最基本的事情,但是您可以覆盖其他非常有用的方法。这些方法是

    willRotateToInterfaceOrientation

    didRotateFromInterfaceOrientation

    willAnimateFirstHalfOfRotationToInterfaceOrientation

    willAnimateSecondHalfOfRotationFromInterfaceOrientation

    前两种方法对于进行旋转的预处理和后处理非常有用。您也许可以在 willRotateToInterfaceOrientation 中初始化视图控制器或将一些视图添加到当前视图。第二个2几乎是不言自明的。如果您想在轮换的特定阶段执行其他操作,您也可以实现它们。

    另一个在使用视图控制器方向时非常有用的代码示例是:

    if(UIInterfaceOrientationIsLandscape(interfaceOrientation)){
    
        //do some processing…
    
    }else if(UIInterfaceOrientationIsPortrait(interfaceOrientation)){
    
        //do different processing…
    }
    else if(UIDeviceOrientationIsValidInterfaceOrientation(interfaceOrientation)){
    
        //do something
    }
    

    注意:here粘贴的描述请查看帖子了解更多详情

    2。此post 将帮助您更改视频方向

    【讨论】:

    • 啊,我明白了。我在 willRotateToInterfaceOrientation 的 interfaceOrientation 上做了一个 switch case。我可以在这里将 AVCaptureVideoPreviewLayer 设置为方向。但是如何设置视频方向?并感谢您的快速回答。
    猜你喜欢
    • 2011-01-13
    • 1970-01-01
    • 2011-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多