Skip to content

Commit

Permalink
Avoid creating an NSError
Browse files Browse the repository at this point in the history
  • Loading branch information
janwiebe-jump committed Nov 5, 2021
1 parent cbb1b0a commit a12b940
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions MediaManager/Platforms/Apple/Player/AppleMediaPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,22 @@ protected virtual void TimeControlStatusChanged(NSObservedChange obj)

protected virtual void DidErrorOcurred(NSNotification obj)
{
//TODO: Error should not be null after this or it will crash.
var error = Player?.CurrentItem?.Error ?? new NSError();
MediaManager.OnMediaItemFailed(this, new MediaItemFailedEventArgs(MediaManager.Queue?.Current, new NSErrorException(error), error?.LocalizedDescription));
Exception exception = null;
string message = null;

var error = Player?.CurrentItem?.Error;
if(error != null)
{
exception = new NSErrorException(error);
message = error.LocalizedDescription;
}
else
{
message = obj?.ToString() ?? "MediaItem failed with unknown reason";
exception = new ApplicationException(message);
}

MediaManager.OnMediaItemFailed(this, new MediaItemFailedEventArgs(MediaManager.Queue?.Current, exception, message));
}

protected virtual async void DidFinishPlaying(NSNotification obj)
Expand Down

0 comments on commit a12b940

Please sign in to comment.