I'm trying to get info about the current playing song in Spotify iOS app. The scenario is as follows: Open Spotify iOS app, start playing a song. Put the app in background and open my iOS app. Is there any way I could get the song playing on Spotify, in my iOS app?
I have tried using the nowPlayingItem property as described in this post, but it didn't work: On iPhone: Find out what song is currently playing? (in the iPod music player)
I have tried using the [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo as described in this post, but it didn't work: Is there a way to access the currently played track while the iPhone is connected to an accessory?
I have seen the same question asked in this post on apple developer forums: https://devforums.apple.com/message/903640#903640.
Has anyone encountered this problem? Have you found a viable solution?
Thanks,
If I'm not wrong, Apple doesn't allow program's to share data (for security reasons). So maybe that's the problem.
Here is a solution in Swift 3:
Note that starting from iOS 10, you must set a description string for
NSAppleMusicUsageDescription
in the Info.plist in order to get access to the user's music.mediaItem
will be an instance ofMPMediaItem
if there is something playing. You can access the media item's attributes using thevalue(forProperty:)
method. This methods takes a property. The properties are defined in the documentation for `MPMediaItem under the heading "General Media Item Property Keys".