MPMusicPlayer Example Fails To Play

Silly me. I code up the Apple Developer example "Playing Audio Using the Built-In Music Player" thinking it might just work but, alas...

I am seeing this error:

"[MPMusicPlayerController play] completed error: Error Domain=MPCPlayerRequestErrorDomain Code=1000 "Failed to send command 0"" When running this code:

class MusicPlayerViewController: UIViewController {


override func viewDidLoad() {

super.viewDidLoad()

let myMediaPlayer = MPMusicPlayerController.applicationQueuePlayer

myMediaPlayer.setQueue(with: MPMediaQuery.songs())

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

return

}

myMediaPlayer.play()

})

}


}

Replies

There are issues with MPMusicPlayerController since iOS11.3 that are still present in iOS 11.4.1 beta and iOS12 beta. Some are listed here:

https://forums.developer.apple.com/thread/96287


I'd encourage you to file a bug report, be polite and say your prayers ;-) I know it can seem hopeless when a basic framework has bugs for so long, but I choose to believe there are many moving parts beyond my understanding, and that someone is working hard to tame the #MPMusicPlayerBeast.