sooper
sooper

Reputation: 6039

Accessing iPod library for use with AVAudioPlayer or remote control events with AVPlayer

I've read many threads on here and haven't yet come across the right one. It's been explained very well that AVAudioPlayer cannot play files from the iPod Library, but does this mean that there's no way at all?

AVPlayer allows you to do this but my issue with it is that you cannot receive remote control events in the background. This is from what I've read so far, but here's the odd thing: I've come across a couple of apps in the App Store that allow you to access your iPod library and play your music in the app, and in the background. It does not use MPMusicPlayerController as it doesn't use the Music app to play songs nor does it stop when entering the background (the app's icon also appears in the multitasking bar). Furthermore you are able to control the app once it's in the background (play/pause/next/prev/vol etc.). This app's volume is somehow 'synched' with the iPod music player volume and I can only assume that it has registered notifications for volume change with MPMusicPlayerControllerVolumeDidChangeNotification.

My questions are: 1. How are they doing it and what class are they using? If they are accessing the iPod library, then it must be AVPlayer. But you cannot receive remote control events with AVPlayer (apart from playerItemDidReachEnd) and so it must be AVAudioPlayer. But you cannot play your iPod library with AVAudioPlayer 2. How are they able to use the volume setting in the iPod library, and how are they keeping it 'synched'.

This thread answer claims that it is possible to access the iPod library with AVPlayer and still receive external events/notifications. How is this? Is he just registering events that you would normally do so with the AVAudioPlayer class?

Very confused about this. Would appreciate some guidance.

Upvotes: 2

Views: 3604

Answers (2)

sooper
sooper

Reputation: 6039

For anyone looking for an answer, I found a great tutorial right here that pretty much sets you on the right path. You have to use AVPlayer but create an Audio Session the same way you would with AVAudioPlayer. Furthermore you need to enable remote events and set your main view controller as the first responder. It's very well explained in the tutorial.

Upvotes: 5

Related Questions