Spotify display now displays part information in the Control Center

I am using the new Spotify SDK in my iOS application. In this, I use the code below to play a song from Spotify. I can play a song. But I can’t see information about the current game and I can’t manage songs from the iOS Control Center. I need to update song information to the Control Center.

[SPTTrack trackWithURI:appDelegate.player.currentTrackURI
               session:auth.session
              callback:^(NSError *error, SPTTrack *track) {

                  self.trackTitle.text = track.name;

                  SPTPartialArtist *artist = [track.artists objectAtIndex:0];
                  self.trackArtist.text = artist.name;

                  appDelegate.currentPlayingSongName = track.name;
                  appDelegate.currentPlayingArtistName = artist.name;

                  //[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = [NSDictionary dictionaryWithObject:track.name forKey: MPMediaItemPropertyTitle];

                  Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");

                  if (playingInfoCenter) {

                      NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];

                      [songInfo setObject:@"Audio Title" forKey:MPMediaItemPropertyTitle];
                      [songInfo setObject:@"Audio Author" forKey:MPMediaItemPropertyArtist];
                      [songInfo setObject:@"Audio Album" forKey:MPMediaItemPropertyAlbumTitle];
                      [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];


                  }

}]; 

Thanks for reading my question. thanks in advance

+4
source share
1 answer

, . . . xcode . , objc. , ;)

//show now playing info:

var player: SPTAudioStreamingController?
let songInfo = [
                MPMediaItemPropertyTitle:  self.player!.currentTrackMetadata[SPTAudioStreamingMetadataTrackName] as! String,
                MPMediaItemPropertyArtist: self.player!.currentTrackMetadata[SPTAudioStreamingMetadataArtistName] as! String,
                MPMediaItemPropertyArtwork: albumArt,
                MPNowPlayingInfoPropertyElapsedPlaybackTime: self.player!.currentPlaybackPosition,
                MPMediaItemPropertyPlaybackDuration: self.player!.currentTrackDuration,
                MPNowPlayingInfoPropertyPlaybackRate:  1.0
            ]
            MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo = songInfo


//setup and receive remote control events:

UIApplication.sharedApplication().beginReceivingRemoteControlEvents()

// then 

override func remoteControlReceivedWithEvent(event: UIEvent?) {
    if event!.type == UIEventType.RemoteControl {
        if event!.subtype == UIEventSubtype.RemoteControlPlay {
            togglePlay()
//etc...
+2

Source: https://habr.com/ru/post/1629867/


All Articles