Is it possible to get data about currently playing track via AirPlay (iOS, Swift)?
My app does not have any player but it communicates with Bluetooth device that can play music. I can get info about current audio track like this:
let systemPlayer = MPMusicPlayerController.systemMusicPlayer
let nowPlayingInfo = systemPlayer.nowPlayingItem
And then just simply get the data like this:
print("title: \(nowPlayingInfo?.title)")
print("album title: \(nowPlayingInfo?.albumTitle)")
print("album artist: \(nowPlayingInfo?.albumArtist)")
print(" artist: \(nowPlayingInfo?.artist)")
However I can get the audio info only if there is something playing from iTunes (local content). When I play something via AirPlay (for example using Spotify) then all I got is just nil
.
How can I get data for each scenario like iOS get in Control Center?:
Look at the audio info
Because Spotify has it's own sandboxed player, you will not be allowed access to it's information.
However, you can use the Spotify SDK to obtain information about the current playing track, if you setup and register for your Spotify app (on your account dashboard).
See this other SO post for more info.