Programmatically get name and artist of currently playing track in Swift
3 answers
This is not an API to get current information about game items from Music or another application, but to tell the system that your application is currently playing something and provide it with the information it needs to display on the lock screen.
So, basically what you are trying to do will not work as you expect.
0
source to share
Have you installed them?
var audioPlayer:MPMoviePlayerController=MPMoviePlayerController()
MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo = [
MPMediaItemPropertyAlbumTitle: "Album Title",
MPMediaItemPropertyTitle: "Title",
MPNowPlayingInfoPropertyElapsedPlaybackTime: audioPlayer.currentPlaybackTime,
MPMediaItemPropertyPlaybackDuration: audioPlayer.duration]
The Playback Information Center now supports the following media element property keys:
-
MPMediaItemPropertyAlbumTitle
-
MPMediaItemPropertyAlbumTrackCount
-
MPMediaItemPropertyAlbumTrackNumber
-
MPMediaItemPropertyArtist
-
MPMediaItemPropertyArtwork
-
MPMediaItemPropertyComposer
-
MPMediaItemPropertyDiscCount
-
MPMediaItemPropertyDiscNumber
-
MPMediaItemPropertyGenre
-
MPMediaItemPropertyPersistentID
-
MPMediaItemPropertyPlaybackDuration
-
MPMediaItemPropertyTitle
-2
source to share