How do I set the title and image of now playing audio in background using the AVPlayer
?
My code so far:
let path: String = String(format: "pathtoaudio")
let aPlayerItem: AVPlayerItem = AVPlayerItem(URL: NSURL(string: path)!)
let anAudioStreamer: AVPlayer = AVPlayer(playerItem: aPlayerItem)
player = anAudioStreamer
let playerController = AVPlayerViewController()
playerController.player = player
self.addChildViewController(playerController)
self.view.addSubview(playerController.view)
playerController.view.frame = self.view.frame
player.addObserver(self, forKeyPath: "status", options: NSKeyValueObservingOptions.New, context: nil)
let nowPlayingInfo = [MPMediaItemPropertyArtist : "Artist!", MPMediaItemPropertyTitle : "Title!", MPMediaItemPropertyArtwork : MPMediaItemArtwork(image: UIImage(named: "nour.jpg")!)]
MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo = nowPlayingInfo
UIApplication.sharedApplication().beginReceivingRemoteControlEvents()
I am trying to use MPNowPlayingInfoCenter
but am not seeing the information on the lock screen.