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

1

9

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...

  • 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 or native iOS controls.
  • The user can traverse (backwards/forward seek) through the queue.
  • 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 app can trigger a track and adjust queue in the background (without user interaction).
  • The audio integrates with native iOS controls (RemoteControlEvents).
  • The app is a "Now Playable App" per Apple's guidelines.

BONUS (if possible yet):

  • App audio can overlay playing music as a directions app does (I realize this may negate 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?

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.

Diaconate answered 10/4, 2020 at 20:15 Comment(0)
L
9

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).

  • You can use either AVPlayer or AVAudioPlayer. AVPlayer has more capabilities. Check Apple's documentation here for AVPlayer. And here for AVAudioPlayer.

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

  • AVAudioPlayer has all the required controls over the played sound file.

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

  • You'll need to use AVQueuePlayer which inherits from AVPlayer. Check apple's docs here.

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

  • It doesn't matter which one you choose from the above. This AVAudioSession options. Check docs here.

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

  • You need to add BackgroundMode capability to you app and check audio, airplay options.

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

  • You'll need to add app extension to manipulates your queuePlayer.

The audio integrates with native iOS controls (RemoteControlEvents).

  • Use MPNowPlayingInfoCenter and update its info to be able to update the song title, artist, artwork, etc... Apple's docs here.

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.

  • Also in AVAudioSession's category options, add .mixWithOthers option.

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.

Lambdacism answered 11/4, 2020 at 15:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.