0

My application works portait, ma i want fullscreen video playback even in landscape mode using the plugin mentionend above.

For this purpose I create a customrenderer to take access to native AVPlayerViewController Ios Control.

I tried in many many ways, but seems to be impossible to handle exit fullscreen event. In that method i want to force layout portrait. I have the code for reset orientation already implemented but the problem is to put the code in the right place.

Any other that faced the same issue??

I tried to search for something useful in AVPlayerView(not accessible), AVPlayerVideoController, AVPlayerCurrentItem etc

Any ideas?

Thanks you in advance.

  • Have you tried the solution like this answer said: https://stackoverflow.com/a/33996932/5474400 ? – Kevin Li Nov 10 '17 at 08:49
  • Thanks for the suggestion, i saw that link before, but i need xamarin c# code ... are you able to translate for me? i will try to addobserver and override che method... – Andrea Cacciatori Nov 13 '17 at 13:10

1 Answers1

0

I have translated the OC code to C# in this link for you, see the following codes:

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");
                    }
                }
            }
        }
Kevin Li
  • 2,258
  • 1
  • 9
  • 18
  • @Andrea, did my answer help you? – Kevin Li Nov 16 '17 at 09:22
  • I Kevin i just tried the code...i was asking me where i have to add the observer (inside OnElementChanged the videoplayer is null) In movedtowindows is valued... btw when i stop in debug, the application never sto in observevalue method inside mycustomrendered when i enter or exit fullscreen... moreover, i read these warning in console is trying to enter/exit full screen, but is not in its view's window's view controller hierarchy. This results in undefined behavior. your code seems to be logic for me but i faced this issue..:( – Andrea Cacciatori Nov 16 '17 at 14:40
  • if you want to help i ask the same to adamfisher here https://github.com/adamfisher/Xamarin.Forms.VideoPlayer/issues/71 – Andrea Cacciatori Nov 16 '17 at 16:59