avplayeravaudioplayermpmusicplayercontrollermpnowplayinginfocentermpremotecommandcenter

Difference between AVAudioPlayer AVPlayer AVQueuePlayer MPMusicPlayerController MPRemoteCommandCenter MPNowPlayingInfoCenter for an iOS 13+ app


All of the threads on this topic are really old (5+ yo), and I can't seem to form a clear MODERN approach, so hopefully this can be summarized for 2020 (Swift 5, Xcode 11).

If you were to build an AUDIO (not just music) player app for the iPhone with iOS 13 in a way that is forward thinking (don't care about anything that won't support iOS 14 - so nothing below 8), what Kits/Classes would you use if the requirements are...

BONUS (if possible yet):

So would you use AVAudioPlayer or AVPlayer or MPMusicPlayerController? MPRemoteCommandCenter or MPNowPlayingInfoCenter?

Perhaps some of the requirements are mutually exclusive, or even impossible, but I can't understand why there are so many methods to control audio playback, with no clear delineation between their use cases, or why it matters if the audio is music or speech, downloaded or streamed. Audio is obviously a second class citizen to video at Apple, especially speech, but I would think there should be some direction by now on certain types of basic applications like playlists, podcasts and other types of audio applications.


Solution

  • I'll try answer your question to the best of my knowledge:

    App can store and play downloaded MP3 files LOCALLY (not necessarily streamed or embedded).

    User has basic player controls over the audio (play/pause/scrub/volume).

    App has an audio queue (order of track play) that can be adjusted at any time by the app.

    User can select to play on bluetooth audio devices phone is paired to.

    The audio can play in the background (when screen is off, or in another app).

    The audio can trigger a track and adjust queue in the background (without user interaction).

    The audio integrates with native iOS controls (RemoteControlEvents).

    In addition to MPRemoteCommandCenter to listen to events and update your player accordingly docs.

    App audio can overlay playing music as a directions app does (I realize this negates the background and "now playing" features, but perhaps it aids the discussion for clearer reasoning to selecting a method for app developers.

    So would you use AVAudioPlayer or AVPlayer or MPMusicPlayerController? MPRemoteCommandCenter or MPNowPlayingInfoCenter?

    Use MPMusicPlayerController if you playing from the device library.

    I think the above summarize the highlights of it. There are many things you should care about when you using these things together not all options works with all AVAudioSession's modes, for example. There are many properties inside the Players, and its setting and the wrong combination might prevent your player from working.