Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 75885

iOS - Playing a video in landscape for a portrait only app

$
0
0

Hello,

I struggled with this for a while and finally figured out a solution, so I'm posting it here for anyone who might find it useful. It's all in how GetSupportedInterfaceOrientations gets implemented in your AppDelegate. It's quite simple really, here's the code that I'm using:

public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations (UIApplication application, UIWindow forWindow)
{
    if (forWindow != null) {
        if (forWindow.RootViewController.PresentedViewController is MediaPlayer.MPMoviePlayerViewController &&
            !forWindow.RootViewController.PresentedViewController.IsBeingDismissed)
        return UIInterfaceOrientationMask.All;
    }

    return UIInterfaceOrientationMask.Portrait;
}

And you display the video player as follows from any of your Forms pages:

#if __IOS__
    var player = new MediaPlayer.MPMoviePlayerViewController (Foundation.NSUrl.FromString (url));
    UIKit.UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(player, true, null);
#endif

Viewing all articles
Browse latest Browse all 75885

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>