0

I'm trying to understand how to handle errors in obj-c on the MediaPlayer and we had someone do some work to do this for us on the AVPlayer but the way that is handled on AVPlayer is different, from what I can see in the documentation, than how errors are handled on the MPMusicPlayerController.

There is something called an MPErrorDomain which is a type of ErrorDomain.

https://developer.apple.com/documentation/mediaplayer/mperrordomain?language=objc

Do I create an observer to listen for when this type of error object occurs?

I am really just looking to understand how to process when one of these errors occur

https://developer.apple.com/documentation/mediaplayer/mperrorcode?language=objc

Ultimately I want to process these error codes https://developer.apple.com/documentation/mediaplayer/mperrorcode?language=objc

1 Answers1

0

Do I create an observer to listen for when this type of error object occurs?

No. You just do stuff and either you get an error or you don't.

Some methods have error parameters in their completion handlers:

https://developer.apple.com/documentation/mediaplayer/mpmusicplayercontroller/2582424-preparetoplay

https://developer.apple.com/documentation/mediaplayer/mpmusicplayerapplicationcontroller/2815055-perform

Apart from that, you'll know you've got an error because the Console will say so (during debugging with Xcode).

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • If I go off of the Error Completion Handler in PrepareToPlay, how do I convert that to the MPErrorCode Type? – Cameron Cintron Oct 30 '19 at 13:27
  • I don't know what you mean by "convert". If you get an error, it's an NSError. It has a domain and a code. Codes are just integers. There is nothing to "convert". – matt Oct 30 '19 at 13:34
  • I looked at what we're doing and I saw that we've already got code to process the error in the completion handlers for preparetoplay but that doesn't seem to throw errors every time. The errors occur when we call play to start the music player – Cameron Cintron Oct 30 '19 at 13:37
  • Well in Objective C you are free to create an exception handler obviously. However the usual thing is to write code that doesn’t throw exceptions. On the other hand I find that the music player throws a lot of silly except hat don’t affect functionality so I ignore them. Anyway we are now way off topic for what you asked. – matt Oct 30 '19 at 13:44