我可以从octane.xam.VideoPlayer插件(XAMARIN FORMS)中拦截退出FullScreen事件吗?

时间:2017-11-09 15:55:31

标签: xamarin.ios xamarin.forms event-handling video-player custom-renderer

我的应用程序工作正常,我想要使用上面的插件提示,即使在横向模式下全屏视频​​播放。

为此,我创建了一个customrenderer来访问本机AVPlayerViewController Ios Control。

我尝试了很多方法,但似乎无法处理退出全屏事件。在那种方法中,我想强制布局肖像。我已经实现了重置方向的代码,但问题是将代码放在正确的位置。

任何其他遇到同样问题的人?

我试图在AVPlayerView(无法访问),AVPlayerVideoController,AVPlayerCurrentItem等中搜索有用的东西

有什么想法吗?

提前谢谢你。

1 个答案:

答案 0 :(得分:0)

我已在此link中将OC代码翻译为C#,请参阅以下代码:

using Foundation;
using CoreGraphics;


playerViewController = new AVPlayerViewController();
playerViewController.ContentOverlayView.AddObserver(this, new NSString("bounds"), NSKeyValueObservingOptions.New | NSKeyValueObservingOptions.Old , IntPtr.Zero);


public override void ObserveValue(NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr context)
        {
            base.ObserveValue(keyPath, ofObject, change, context);

            if(ofObject == playerViewController.ContentOverlayView)
            {
                if(keyPath == "bounds")
                {
                    NSValue oldRect = change.ValueForKey(new NSString("NSKeyValueChangeOldKey")) as NSValue;
                    NSValue newRect = change.ValueForKey(new NSString("NSKeyValueChangeNewKey")) as NSValue;
                    CGRect oldBounds = oldRect.CGRectValue;
                    CGRect newBounds = newRect.CGRectValue;

                    bool wasFullscreen = CGRect.Equals(oldBounds, UIScreen.MainScreen.Bounds);
                    bool isFullscreen = CGRect.Equals(newBounds, UIScreen.MainScreen.Bounds);

                    if(isFullscreen && !wasFullscreen)
                    {
                        if(CGRect.Equals(oldBounds,new CGRect(0,0,newBounds.Size.Height, newBounds.Size.Width)))
                        {
                            Console.WriteLine("rotated fullscreen");
                        }
                        else
                        {
                            Console.WriteLine("entered fullscreen");
                        }
                    }
                    else if(!isFullscreen && wasFullscreen)
                    {
                        Console.WriteLine("exited fullscreen");
                    }
                }
            }
        }