-->

I need to know how to get information about which

2019-08-10 19:27发布

问题:

I can get information (artist, album, title) of the song that is currently playing with:

let t = MPMusicPlayerController().nowPlayingItem?.title

It works fine when the music is streaming from the iOS Music Player. However, when the streaming is from other source (Spotify, Napster, Youtube, Tuneinradio, etc.) I can not get information. How can I get this information for any app?

回答1:

Use the nowPlayingInfo dictionary on MPNowPlayingInfoCenter.defaultCenter():

let t = MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo[MPMediaItemPropertyTitle]

MPNowPlayingInfoCenter class reference here.