【问题标题】:Display Spotify now playing item info in Control Center显示 Spotify 现在在控制中心播放项目信息
【发布时间】:2016-06-03 16:04:47
【问题描述】:

我在我的 iOS 应用中使用新的 SDK for Spotify。在此,我使用以下代码从 Spotify 播放歌曲。我可以播放歌曲。但我无法看到正在播放的歌曲信息,也无法从 iOS 控制中心控制歌曲。我需要将歌曲信息更新到控制中心。

[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];


                  }

}]; 

感谢您阅读我的问题。提前致谢

【问题讨论】:

    标签: ios objective-c spotify control-center


    【解决方案1】:

    我昨天找到您的帖子时正在寻找相同的信息。从那以后我就明白了。但这很快。我刚刚开始学习 xcode 和 swift。所以不知道如何在 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...
    

    【讨论】:

    • 谢谢。会检查并通知您
    • 请查看我的帖子。你的和我的一样
    • 您缺少 MPMediaItemPropertyArtwork。我认为需要在控制中心和锁定屏幕上为我显示正在播放的信息。
    • 无论如何谢谢。我错过了 beginReceivingRemoteControlEvents 方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    相关资源
    最近更新 更多