Ios 锁屏不支持nowPlayingInfo字典

Ios 锁屏不支持nowPlayingInfo字典,ios,objective-c,mpnowplayinginfocenter,Ios,Objective C,Mpnowplayinginfocenter,我试图让我的播客应用程序在锁定屏幕上显示内容,同时尊重播放/暂停控制。这是我的密码: - (void)playEpisodeAtIndex:(NSInteger)index { _currentIndex = index; TalkPodEpisode *episode = self.playlist[index]; self.player = [[AVPlayer alloc] initWithURL:episode.url]; [self.player pl

我试图让我的播客应用程序在锁定屏幕上显示内容,同时尊重播放/暂停控制。这是我的密码:

- (void)playEpisodeAtIndex:(NSInteger)index {

    _currentIndex = index;
    TalkPodEpisode *episode = self.playlist[index];
    self.player = [[AVPlayer alloc] initWithURL:episode.url];
    [self.player play];
    _playing = YES;

    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

    NSDictionary *lockScreenInfo = @{MPMediaItemPropertyTitle:self.currentEpisode.title,
                                 MPMediaItemPropertyArtist: @"The Talk Pod",
                                 MPNowPlayingInfoPropertyPlaybackRate:[NSNumber numberWithDouble:self.player.rate],
                                          MPNowPlayingInfoPropertyElapsedPlaybackTime:[NSNumber numberWithDouble:[self currentPlaybackTime]]};
    [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = lockScreenInfo;


}
奇怪的是,发生了这样的事情:

  • 响应和处理事件工作正常
  • 艺术家和标题显示在锁定屏幕上
  • 进度滑块显示--:--并且不显示播放进度
  • 这一集的持续时间也不会出现
  • 以下是获取当前运行时间的代码:

    - (NSTimeInterval)currentPlaybackTime {
    
        CMTime time = self.player.currentTime;
        if (CMTIME_IS_VALID(time)) {
    
            return time.value/time.timescale;
    
        }
    
        return 0;
    
    }
    
    以下是切换播放和暂停的代码:

    - (void)playPause {
    
        if (self.player) {
    
            if (_playing) {
    
                [self.player pause];
                _playing = NO;
    
            } else {
    
                [self.player play];
                _playing = YES;
    
            }
    
            NSMutableDictionary *lockScreenInfo = [[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo mutableCopy];
            lockScreenInfo[MPNowPlayingInfoPropertyPlaybackRate] = [NSNumber numberWithDouble:self.player.rate];
            lockScreenInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = [NSNumber numberWithDouble:[self currentPlaybackTime]];
            [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = lockScreenInfo;
    
        }
    
    }
    

    有人知道怎么解决这个问题吗?让我困惑的是,屏幕上显示了一些内容,但当前的播放信息却没有。同样,接收和处理事件工作正常。

    可能需要在nowPlayingInfo字典中设置播放持续时间键。 另一个问题请看我的帖子,它在我的应用程序中运行良好。