Beispiel #1
0
 protected override void OnElementChanged(ElementChangedEventArgs <VideoPlayer> e)
 {
     base.OnElementChanged(e);
     if (Control == null)
     {
         _timer          = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds);
         _timer.Elapsed += _timer_Elapsed;
     }
     if (e.OldElement != null)
     {
         _timer?.Stop();
         _timer?.Dispose();
         _timer = null;
         _asset?.Dispose();
         _asset = null;
         _playerItem?.Dispose();
         _playerItem = null;
         _player?.Dispose();
         _player = null;
         _playerLayer?.Dispose();
         _playerLayer = null;
     }
     if (e.NewElement != null)
     {
     }
 }
Beispiel #2
0
 private void CleanPlayerItem()
 {
     _PlayerItem.RemoveObserver(this, _status);
     _PlayerItem.RemoveObserver(this, _error);
     _Asset.Dispose();
     _PlayerItem.Dispose();
 }
 protected override void Dispose(bool disposing)
 {
     base.Dispose(disposing);
     _player?.Dispose();
     _playerLayer?.Dispose();
     _playerItem?.Dispose();
     _asset?.Dispose();
     _timeObserver?.Dispose();
 }
Beispiel #4
0
 public void Open(string videoFileName)
 {
     _playerLoaded = false;
     if (_player != null)
     {
         try
         {
             _player.Pause();
             _player.Dispose();
             _player = null;
             foreach (var subView in View.VideoView.Subviews)
             {
                 subView.RemoveFromSuperview();
             }
             foreach (var subLayer in View.VideoView.Layer.Sublayers)
             {
                 subLayer.RemoveFromSuperLayer();
             }
             _playerLayer.Dispose();
             _playerItem.Dispose();
             _asset.Dispose();
         }
         catch
         {
         }
     }
     ShowPlayImage(false);
     _asset                = AVAsset.FromUrl(NSUrl.FromFilename(videoFileName));
     _playerItem           = new AVPlayerItem(_asset);
     _player               = new AVPlayer(_playerItem);
     _playerLayer          = AVPlayerLayer.FromPlayer(_player);
     _videoView            = new NSMyVideoView(new CoreGraphics.CGRect(0, 0, View.VideoView.Frame.Width, View.VideoView.Frame.Width), View.VideoView, _playerLayer);
     _videoView.WantsLayer = true;
     View.VideoView.AddSubview(_videoView);
     View.VideoView.WantsLayer = true;
     _playerLayer.Frame        = View.VideoView.Bounds;
     View.VideoView.Layer.AddSublayer(_playerLayer);
     _videoView.ResizeWithCorrectAspectRatio();
     _playerLoaded = true;
 }
Beispiel #5
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_playbackEndedObserver != null)
                {
                    NSNotificationCenter.DefaultCenter.RemoveObserver(_playbackEndedObserver);
                    _playbackEndedObserver.Dispose();
                }

                Player?.Pause();
                PlayerLayer.Player = null;
                Player?.ReplaceCurrentItemWithPlayerItem(null);

                _item?.Dispose();
                _item = null;

                _asset?.Dispose();
                _asset = null;
            }
            base.Dispose(disposing);
        }