Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current playing song from Spotify iOS app

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,

like image 443
buddy Avatar asked Dec 11 '13 06:12

buddy


People also ask

How do you see what is currently playing on Spotify?

Control what plays with the Now Playing bar at the bottom of the app. Tip: On mobile, find Now Playing just above the menu bar. Tap it for a bigger view.

What song is currently playing?

To identify songs, open Control Center, then tap the Shazam button . Shazam can identify songs playing on your device even when you're using headphones. To find songs you've identified, touch and hold the Shazam button in Control Center to open your History View.

How do you preview songs on Spotify app?

Using the feature is simple; you just have to hold down your finger on any song, album, artist or playlist. The music will start instantly and you can drag your finger around on the screen to play any other songs listed. Lift your finger off and it will stop.


1 Answers

Here is a solution in Swift 3:

let player = MPMusicPlayerController.systemMusicPlayer() if let mediaItem = player.nowPlayingItem {     let title: String = mediaItem.value(forProperty: MPMediaItemPropertyTitle) as! String     let albumTitle: String = mediaItem.value(forProperty: MPMediaItemPropertyAlbumTitle) as! String     let artist: String = mediaItem.value(forProperty: MPMediaItemPropertyArtist) as! String      print("\(title) on \(albumTitle) by \(artist)") } 

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 of MPMediaItem if there is something playing. You can access the media item's attributes using the value(forProperty:) method. This methods takes a property. The properties are defined in the documentation for `MPMediaItem under the heading "General Media Item Property Keys".

like image 100
Devin Brown Avatar answered Sep 20 '22 15:09

Devin Brown