我没有找到如何从锁定屏幕iOS 7回放歌曲的方式.音量滑块可用,所有按钮都正常工作,但上部滑块不可用!
AVPlayer是我正在使用的类.
任何帮助表示赞赏!
解决方法
您需要在“正在播放的信息”中设置此项.
每当项目(轨道)改变时,做类似的事情
NSMutableDictionary *nowPlayingInfo = [[NSMutableDictionary alloc] init]; [nowPlayingInfo setObject:track.artistName forKey:MPMediaItemPropertyArtist]; [nowPlayingInfo setObject:track.trackTitle forKey:MPMediaItemPropertyTitle]; ... [nowPlayingInfo setObject:[NSNumber numberWithDouble:self.player.rate] forKey:MPNowPlayingInfoPropertyPlaybackRate]; [nowPlayingInfo setObject:[NSNumber numberWithDouble:self.currentPlaybackTime] forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime]; [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = nowPlayingInfo;
每当播放速率改变(播放/暂停)时,执行
NSMutableDictionary *nowPlayingInfo = [[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo mutableCopy]; [nowPlayingInfo setObject:[NSNumber numberWithDouble:self.player.rate] forKey:MPNowPlayingInfoPropertyPlaybackRate]; [nowPlayingInfo setObject:[NSNumber numberWithDouble:self.currentPlaybackTime] forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime]; [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = nowPlayingInfo;
您可以像这样获得当前的播放时间:
- (NSTimeInterval)currentPlaybackTime { CMTime time = self.player.currentTime; if (CMTIME_IS_VALID(time)) { return time.value / time.timescale; } return 0; }