#pragma mark - 设置锁频播放时显示的信息 ----
- (void)setLockScreenPlayingInfo:(NSNumber *)playbackRate {
if (self.courseIndex >= self.courseModel.courses.count) {
return;
}
// 下面构建锁屏信息时,需使用弱应用weakSelf,负责会导致内存泄露
__weak typeof(self) weakSelf = self;
MPMediaItemArtwork *artWork = [[MPMediaItemArtwork alloc] initWithBoundsSize:CGSizeMake(100, 100) requestHandler:^UIImage *_Nonnull (CGSize size) {
return weakSelf.iconImage;
}];
MTCourse *course = weakSelf.courseModel.courses[weakSelf.courseIndex];
NSDictionary *artDic = @{ MPMediaItemPropertyTitle: course.spot.spotName,
MPMediaItemPropertyArtist: course.spot.countryName,
MPMediaItemPropertyArtwork: artWork,
MPMediaItemPropertyPlaybackDuration: @(weakSelf.voicePlayManager.audioPlayer.duration),
MPNowPlayingInfoPropertyElapsedPlaybackTime: @(weakSelf.voicePlayManager.audioPlayer.currentTime),
MPNowPlayingInfoPropertyPlaybackRate: playbackRate};
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:artDic];
//播放
MPRemoteCommand *playCommand = [MPRemoteCommandCenter sharedCommandCenter].playCommand;
[playCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent *event) {
return MPRemoteCommandHandlerStatusSuccess;
}];
//暂停
MPRemoteCommand *pauseCommand = [MPRemoteCommandCenter sharedCommandCenter].pauseCommand;
[pauseCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent *event) {
return MPRemoteCommandHandlerStatusSuccess;
}];
}
网友评论