private void TryDisposePlayer() { if (_player != null) { try { _videoLayer.RemoveObserver(this, new NSString("videoRect"), _videoLayer.Handle); _videoLayer.RemoveFromSuperLayer(); _player.CurrentItem?.RemoveObserver(this, new NSString("loadedTimeRanges"), _player.Handle); _player.CurrentItem?.RemoveObserver(this, new NSString("status"), _player.Handle); _player.CurrentItem?.RemoveObserver(this, new NSString("duration"), _player.Handle); _player.RemoveObserver(this, new NSString("rate"), RateObservationContext.Handle); _player.RemoveTimeObserver(_periodicTimeObserverObject); _player.RemoveAllItems(); } finally { _itemFailedToPlayToEndTimeNotification?.Dispose(); _playbackStalledNotification?.Dispose(); _didPlayToEndTimeNotification?.Dispose(); _videoLayer?.Dispose(); _player?.CurrentItem?.Dispose(); _player?.Dispose(); _player = null; } } }
public void PhotoLibraryDidChange(PHChange changeInstance) { // Call might come on any background queue. Re-dispatch to the main queue to handle it. DispatchQueue.MainQueue.DispatchAsync(() => { // Check if there are changes to the asset we're displaying. PHObjectChangeDetails changeDetails = changeInstance.GetObjectChangeDetails(Asset); if (changeDetails == null) { return; } // Get the updated asset. // TODO: check return type. Catch! ObjectAfterChanges should be PHObject instead of NSObject https://bugzilla.xamarin.com/show_bug.cgi?id=35540 Asset = (PHAsset)changeDetails.ObjectAfterChanges; if (Asset != null) { FavoriteButton.Title = Asset.Favorite ? "♥︎" : "♡"; } // If the asset's content changed, update the image and stop any video playback. if (changeDetails.AssetContentChanged) { UpdateImage(); playerLayer?.RemoveFromSuperLayer(); playerLayer = null; } }); }
void RemovePlayerLayer() { if (playerLayer != null) { playerLayer.Player.Pause(); playerLayer.RemoveFromSuperLayer(); playerLayer.Dispose(); } }
private void stopPlaying(Object sender, EventArgs ea) { _player.Pause(); _playerLayer.RemoveFromSuperLayer(); //remove subviews foreach (var view in this.View.Subviews) { view.RemoveFromSuperview(); } this.btnDonePlaying.TouchUpInside -= stopPlaying; }
public void PhotoLibraryDidChange(PHChange changeInstance) { // Call might come on any background queue. Re-dispatch to the main queue to handle it. DispatchQueue.MainQueue.DispatchAsync(() => { // Check if there are changes to the asset we're displaying. PHObjectChangeDetails changeDetails = changeInstance.GetObjectChangeDetails(Asset); if (changeDetails == null) { return; } // Get the updated asset. var assetAfterChanges = changeDetails.ObjectAfterChanges as PHAsset; if (assetAfterChanges == null) { return; } Asset = (PHAsset)assetAfterChanges; if (Asset != null) { FavoriteButton.Title = Asset.Favorite ? "♥︎" : "♡"; } // If the asset's content changed, update the image and stop any video playback. if (changeDetails.AssetContentChanged) { UpdateContent(); playerLayer?.RemoveFromSuperLayer(); playerLayer = null; playerLooper = null; } }); }