0

I want to display the track info in a nowPlayingTemplate, how can i send it the info or configure it?

This is my code:

itemLista = CPListItem(text: podcast.name, detailText: podcast.date)
itemLista.handler = { [weak self] item, completion in
    

       guard let this = self else { return }

        let nowPlayingTemplate = CPNowPlayingTemplate.shared
                    nowPlayingTemplate.add(this)

        this.playWithItems(items: [podcast.identifier!])

        var nowPlayingInfo = [String: Any]()
        nowPlayingInfo[MPMediaItemPropertyTitle] = "Title"
        nowPlayingInfo[MPMediaItemPropertyArtist] = "Artist"
    
        MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo

        this.interfaceController!.pushTemplate(nowPlayingTemplate, animated: true, completion: nil)
    
        completion()
  }


func playWithItems(items: [String]) {

    MPMusicPlayerController.applicationQueuePlayer.pause()
    MPMusicPlayerController.applicationQueuePlayer.setQueue(with: items)
    MPMusicPlayerController.applicationQueuePlayer.prepareToPlay()
    MPMusicPlayerController.applicationQueuePlayer.play()
}

screenshot

1 Answers1

0

The information gets populated from the MPNowPlayingInfoCenter. You have to import MediaPlayer and set the info like this:

var nowPlayingInfo = [String: Any]()
nowPlayingInfo[MPMediaItemPropertyTitle] = "Title"
nowPlayingInfo[MPMediaItemPropertyArtist] = "Artist"

MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo
fruitcoder
  • 1,073
  • 8
  • 24