【问题标题】:Lock Screen not respecting nowPlayingInfo dictionary锁定屏幕不尊重 nowPlayingInfo 字典
【发布时间】:2015-04-06 00:40:32
【问题描述】:

我正在尝试让我的播客应用在锁定屏幕中显示内容,并尊重播放/暂停控件。这是我的代码:

- (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;


}

奇怪的是,发生了什么:

  1. 响应和处理事件工作正常
  2. 艺术家和标题显示在锁定屏幕上
  3. 进度滑块显示--:--,不显示播放进度
  4. 剧集的持续时间也不会出现。

这里是获取当前经过时间的代码:

- (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;

    }

}

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

【问题讨论】:

    标签: ios objective-c mpnowplayinginfocenter


    【解决方案1】:

    您可能需要在 nowPlayingInfo 字典中设置 Playback Duration 键。 查看我的帖子以了解另一个问题,它在我的应用程序中运行良好。 Stack : Show seek track duration on control center

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-15
      • 2016-05-28
      • 1970-01-01
      • 1970-01-01
      • 2011-04-16
      • 2011-10-18
      • 2011-06-08
      • 1970-01-01
      相关资源
      最近更新 更多