I've got a command object called PlayVideoCommand
that leverages the native video players.
Android is working as expected, whereby the video plays in whatever video player one chooses, and when the video is finished, you're returned to exactly where you left off.
On iOS however, when the video completes, you're returned to where you left off and then the view is popped, and you're taken [back] a level. Is there a way to prevent this?
Here's my Android video player
public class NativeVideoPlayer : IVideoPlayer
{
private readonly Context _context;
public NativeVideoPlayer ()
{
_context = Android.App.Application.Context;
}
public void Play ( string url, string mimeType )
{
var uri = Uri.Parse( url );
_context.Intent( uri, mimeType ).AsActionView().StartIntent();
}
}
public static class IntentHelperExtensions
{
private static Intent _intent;
public static Context Intent(this Context context, Uri uri, string mimeType)
{
Init();
_intent.SetDataAndType(uri, mimeType);
return context;
}
public static Context Intent(this Context context, Uri uri)
{
Init();
_intent.SetData(uri);
return context;
}
public static Context AsActionView(this Context context)
{
_intent.SetAction(Android.Content.Intent.ActionView);
return context;
}
public static void StartIntent(this Context context)
{
context.StartActivity(_intent);
}
private static void Init()
{
_intent = new Intent();
_intent.SetFlags(ActivityFlags.NewTask);
}
}
And here's my misbehaving iOS video player
public class NativeVideoPlayer : IVideoPlayer
{
public void Play(string url, string mimeType)
{
var videoPath = new NSUrl(url);
var player = new MPMoviePlayerController(videoPath);
var root = UIApplication.SharedApplication.KeyWindow.RootViewController.View;
root.AddSubview(player.View);
player.AllowsAirPlay = true;
player.SetFullscreen(true, true);
player.ControlStyle = MPMovieControlStyle.Fullscreen;
player.PrepareToPlay();
player.Play();
}
}
What would I need to do in order to prevent that unnecessary pop?