I'm designing a music app that plays music from the user's iPhone music library and I'm having problems figuring out which audio player is the right one to use for it (AVAudioPlayer, AVPlayer, or MPMusicPlayer).
My app needs to do the following:
From my research it seems like each of the three audio players mentioned above do SOME of the tasks required for my app, but none of them do ALL of them. AVPlayer seems to get the closest, except its volume is dependent on the device/system volume.
Does anyone have any recommendations or workarounds to accomplish this? I've been wracking my brain over this for quite some time so any help at all would be appreciated.
EDIT
The MPMusicPlayerController class does not actually support playing background audio when getting an instance of it via + applicationMusicPlayer
. The best option, then, is to simply use MPMusicPlayer to query the iPod music library. Once a song is selected by the user, the resulting MPMediaItem
can be queried for it's asset URL and fed into AVPlayer's +playerWithURL
, giving you full control of playback parameters.
--
I would recommend MPMusicPlayerController.
-applicationMusicPlayer
to get a local copy of the iPod singleton; from there, you can control its volume by setting its volume
property for just your application.Playing background audio
in http://www.sagorin.org/2011/11/29/ios-playing-audio-in-background-audio/)MPMusicPlayerController
object. This way, you can be notified whenever the nowPlayingItem
property is changed.Hopefully this high-level description suffices. Let me know if you need any further clarification.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With