Beispiel #1
0
 internal void UpdateVideoGravity(AVLayerVideoGravity gravity)
 {
     if (_videoLayer != null)
     {
         _videoLayer.VideoGravity = gravity;
     }
 }
Beispiel #2
0
		static internal NSString EnumToKey (AVLayerVideoGravity vg)
		{
			switch (vg) {
			case AVLayerVideoGravity.ResizeAspect:
				return AVPlayerLayer.GravityResizeAspect;
			case AVLayerVideoGravity.ResizeAspectFill:
				return AVPlayerLayer.GravityResizeAspectFill;
			case AVLayerVideoGravity.Resize:
				return AVPlayerLayer.GravityResize;
			default:
				return null;
			}
		}
        static internal NSString EnumToKey(AVLayerVideoGravity vg)
        {
            switch (vg)
            {
            case AVLayerVideoGravity.ResizeAspect:
                return(AVPlayerLayer.GravityResizeAspect);

            case AVLayerVideoGravity.ResizeAspectFill:
                return(AVPlayerLayer.GravityResizeAspectFill);

            case AVLayerVideoGravity.Resize:
                return(AVPlayerLayer.GravityResize);

            default:
                return(null);
            }
        }
Beispiel #4
0
        private CGRect VideoPreviewBoxForGravity(AVLayerVideoGravity gravity, CGSize frameSize, CGSize apertureSize)
        {
            var apertureRatio = apertureSize.Height / apertureSize.Width;
            var viewRatio     = frameSize.Width / frameSize.Height;

            CGSize size = CGSize.Empty;

            if (gravity == AVLayerVideoGravity.ResizeAspectFill)
            {
                if (viewRatio > apertureRatio)
                {
                    size.Width  = frameSize.Width;
                    size.Height = apertureSize.Width * (frameSize.Width / apertureSize.Height);
                }
                else
                {
                    size.Width  = apertureSize.Height * (frameSize.Height / apertureSize.Width);
                    size.Height = frameSize.Height;
                }
            }
            else if (gravity == AVLayerVideoGravity.ResizeAspect)
            {
                if (viewRatio > apertureRatio)
                {
                    size.Width  = apertureSize.Height * (frameSize.Height / apertureSize.Width);
                    size.Height = frameSize.Height;
                }
                else
                {
                    size.Width  = frameSize.Width;
                    size.Height = apertureSize.Width * (frameSize.Width / apertureSize.Height);
                }
            }
            else if (gravity == AVLayerVideoGravity.Resize)
            {
                size.Width  = frameSize.Width;
                size.Height = frameSize.Height;
            }


            CGRect videoBox = CGRect.Empty;

            videoBox.Size = size;
            if (size.Width < frameSize.Width)
            {
                videoBox.X = (frameSize.Width - size.Width) / 2;
            }
            else
            {
                videoBox.X = (size.Width - frameSize.Width) / 2;
            }

            if (size.Height < frameSize.Height)
            {
                videoBox.Y = (frameSize.Height - size.Height) / 2;
            }
            else
            {
                videoBox.Y = (size.Height - frameSize.Height) / 2;
            }

            return(videoBox);
        }