MPMusicPlayerController.systemMusicPlayer.prepareToPlay never invokes callback

Number:rdar://29314216 Date Originated:17-Nov-2016 10:45 AM
Status:Open Resolved:
Product:iOS SDK Product Version:10.1.1
Classification:Enhancement Reproducible:Always
Attempting to use the `prepareToPlay(completionHandler:)` method on `MPMusicPlayerController.systemMusicPlayer()` fails because the callback is never invoked.

Steps to Reproduce:
Invoke the `prepareToPlay(completionHandler:)` method on `MPMusicPlayerController.systemMusicPlayer()`
Sample code in the context of a view controller:

override func viewDidLoad() {
    MPMediaLibrary.requestAuthorization { (status) in
        switch status {
        case .authorized:
            let musicPlayerController: MPMusicPlayerController = MPMusicPlayerController.systemMusicPlayer()
            musicPlayerController.setQueue(with: MPMediaQuery.songs())
            NSLog("About to call prepareToPlay")
            musicPlayerController.prepareToPlay(completionHandler: { (error) in
                guard error == nil else {
                    let alert = UIAlertController(title: "Error", message: "Error preparing to play. \(error!.localizedDescription)", preferredStyle: .alert)
                    alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
                    self.present(alert, animated: true, completion: nil)
                NSLog("Ready to play")
        case .denied, .notDetermined, .restricted:
            let alert = UIAlertController(title: "Access Denied", message: "You need to allow access to the media library.", preferredStyle: .alert)
            alert.addAction(UIAlertAction(title: "Settings", style: .default, handler: { (action) in
            self.present(alert, animated: true, completion: nil)

Expected Results:

Console logs:
`About to call prepareToPlay`
`Ready to play`

Music plays.

Actual Results:

Console logs:
`About to call prepareToPlay`

No music plays and no error is displayed.


Tested with iOS 10.1.1 on iPhone 6 and iPhone SE



Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!