MPMoviePlayerController strange behavior
I 've been working on playing a video from a URL using the MPMoviePlayerController object. However when playback return from FullScreen mode, the MPMoviePlayerController black bands will appear at the top and bottom. I tried to solve using AspectFill without any result. In addition , returning the FullScreen Status bar disappears. Greetings. Thanks .. Attach my Custom Renderer code and image app.
[assembly: ExportRenderer(typeof(VideoViewOS), typeof(VideoViewOSRenderer))]
namespace Clazloop.iOS
{
public class VideoViewOSRenderer : ViewRenderer<VideoViewOS, UIView>
{
MPMoviePlayerController _player;
private List _observers = new List ();
protected override void OnElementChanged (ElementChangedEventArgs<VideoViewOS> e)
{
base.OnElementChanged (e);
if (e.NewElement != null)
{
if (base.Control == null)
{
_player = new MPMoviePlayerController();
_player.View.Frame = this.Bounds;
_player.ScalingMode = MPMovieScalingMode.AspectFill;
_player.ShouldAutoplay = false;
base.SetNativeControl(_player.View);
var center = NSNotificationCenter.DefaultCenter;
_observers.Add(center.AddObserver((NSString)"UIDeviceOrientationDidChangeNotification", DeviceRotated));
_observers.Add(center.AddObserver(MPMoviePlayerController.PlaybackStateDidChangeNotification, OnLoadStateChanged));
_observers.Add(center.AddObserver(MPMoviePlayerController.PlaybackDidFinishNotification, OnPlaybackComplete));
_observers.Add(center.AddObserver(MPMoviePlayerController.WillExitFullscreenNotification, OnExitFullscreen));
_observers.Add(center.AddObserver(MPMoviePlayerController.WillEnterFullscreenNotification, OnEnterFullscreen));
ToggleFullscreen ();
}
}
VideoPath();
Fullscreen();
}
private void DeviceRotated(NSNotification notification)
{
ToggleFullscreen ();
}
private void OnLoadStateChanged (NSNotification notification) { }
private void OnPlaybackComplete(NSNotification notification) { }
private void OnExitFullscreen(NSNotification notification) { }
private void OnEnterFullscreen (NSNotification notification) { }
private void ToggleFullscreen()
{
_player.ScalingMode = MPMovieScalingMode.None;
_player.ScalingMode = MPMovieScalingMode.AspectFill;
switch (UIDevice.CurrentDevice.Orientation)
{
case UIDeviceOrientation.Portrait:
_player?.SetFullscreen(false, false);
break;
case UIDeviceOrientation.PortraitUpsideDown:
_player?.SetFullscreen (false, false);
break;
case UIDeviceOrientation.LandscapeLeft:
_player?.SetFullscreen(true, false);
break;
case UIDeviceOrientation.LandscapeRight:
_player?.SetFullscreen(true, false);
break;
}
_player.View.SetNeedsLayout();
_player.View.SetNeedsDisplay();
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == VideoViewOS.VideoSourceProperty.PropertyName) updateVideoPath();
if (e.PropertyName == VideoViewOS.FullscreenProperty.PropertyName) updateFullscreen();
}
public override void MovedToSuperview()
{
base.MovedToSuperview();
}
private void VideoPath()
{
if (_player == null) return;
_player.ControlStyle = MPMovieControlStyle.Embedded;
_player.ScalingMode = MPMovieScalingMode.AspectFill;
_player.BackgroundView.BackgroundColor = UIColor.Clear;
_player.ShouldAutoplay = true;
_player.ContentUrl = !string.IsNullOrWhiteSpace(this.Element.VideoSource) ? NSUrl.FromString(this.Element.VideoSource) : null;
_player.PrepareToPlay();
UIApplication.SharedApplication.SetStatusBarHidden(false, false);
}
private void Fullscreen()
{
if (_player == null) return;
_player.SetFullscreen(this.Element.Fullscreen, true);
_player.View.SetNeedsLayout();
_player.View.SetNeedsDisplay();
}
protected override void Dispose(bool disposing)
{
if (this._player != null)
{
this._player.Dispose();
this._player = null;
}
base.Dispose(disposing);
}
}
}