Skip to content

Commit

Permalink
Merge pull request #819 from jamsoft/develop
Browse files Browse the repository at this point in the history
Fixes #629 and Tidied up the code from Jearom.
  • Loading branch information
martijn00 authored Jun 9, 2021
2 parents 0c71ade + 05f8dd0 commit 654dc2b
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions MediaManager/Platforms/Ios/Video/PlayerViewController.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
using AVKit;
using System;
using AVKit;
using CoreGraphics;
using Foundation;
using UIKit;

namespace MediaManager.Platforms.Ios.Video
{
public class PlayerViewController : AVPlayerViewController
{
private const string KeyPath = "contentOverlayView.frame";

private bool _savePlayer;

protected static MediaManagerImplementation MediaManager => CrossMediaManager.Apple;

public PlayerViewController()
{
AddObserver(this, KeyPath, NSKeyValueObservingOptions.OldNew, Handle);
}

public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
Expand All @@ -23,7 +36,34 @@ public override void ViewWillDisappear(bool animated)
MediaManager.MediaPlayer.VideoView = null;
}

Player = null;
if (!_savePlayer)
{
Player = null;
}
}

public override void ObserveValue(NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr context)
{
if (keyPath != KeyPath || change == null || change[ChangeOldKey] == null) return;

var oldNsValue = change[ChangeOldKey];
var newNsValue = change[ChangeNewKey];

if (oldNsValue == null || newNsValue == null) return;

var oldValue = ((NSValue) oldNsValue).CGRectValue;
var newValue = ((NSValue) newNsValue).CGRectValue;

if (oldValue == CGRect.Empty || oldValue == CGRect.Null || oldValue.Equals(newValue)) return;

if (UIScreen.MainScreen.Bounds.Height > UIScreen.MainScreen.Bounds.Width)
{
_savePlayer = newValue.Y >= oldValue.Y;
}
else
{
_savePlayer = newValue.Height >= UIScreen.MainScreen.Bounds.Height;
}
}
}
}

0 comments on commit 654dc2b

Please sign in to comment.