我正在尝试在暂停播放时使MPNowPlayingInfoCenter正常工作。(我有一个使用AVPlayer进行播放的流媒体音乐应用程序,并且我正在通过Airplay在我的Apple TV上进行播放。)除了暂停之外,似乎一切都能正确地反映在Apple TV的用户界面上。我是这样初始化它的:
MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter];
NSDictionary *songInfo = @{
MPMediaItemPropertyTitle: title,
MPMediaItemPropertyArtist: artist
};
center.nowPlayingInfo = songInfo;
由于我正在流媒体,所以在开始播放时没有持续时间信息。当我从流媒体中获得“准备就绪”的信号时,我会更新持续时间,在我的Apple TV上显示正确:
MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter];
NSMutableDictionary *playingInfo = [NSMutableDictionary dictionaryWithDictionary:center.nowPlayingInfo];
[playingInfo setObject:[NSNumber numberWithFloat:length] forKey:MPMediaItemPropertyPlaybackDuration];
center.nowPlayingInfo = playingInfo;
当用户查找曲目时,我也可以使用这种技术进行查找:
[playingInfo setObject:[NSNumber numberWithFloat:length * targetProgress] forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime];
我无法弄清楚的一件事是如何暂停我的Apple TV上的播放头。 当用户在我的UI中点击暂停时,我正在尝试做类似以下的事情:
The one thing I can NOT figure out is, how to pause the playhead on my Apple TV. When user taps pause in my UI, I am trying to do something like:
MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter];
NSMutableDictionary *playingInfo = [NSMutableDictionary dictionaryWithDictionary:center.nowPlayingInfo];
[playingInfo setObject:[NSNumber numberWithFloat:0.0f] forKey:MPNowPlayingInfoPropertyPlaybackRate];
center.nowPlayingInfo = playingInfo;
与其暂停,这将播放头寻回到零并继续推进。
如何在我的Apple TV界面中正确暂停播放头?
[player pause];
,其中player
是一个 AVPlayer 实例。它在 Apple TV UI 中没有影响。音频实际上停止并按预期恢复播放,但是播放进度存在我描述的问题。 - Jaanus[playingInfo setObject:[NSNumber numberWithFloat:0.000001f] forKey:MPNowPlayingInfoPropertyPlaybackRate];
的东西? - Aaron Brager