现在,我为iOS 10.0开发音乐应用程序。 启动音乐,应用程序进入背景,锁定屏幕显示图稿以及播放/暂停按钮和滑块。 因此,我更改了滑块位置,但是这样做之后,经过的播放时间停止了。 (默认的音乐应用程序(由Apple提供)不会停止经过的播放时间)
如何重新开始经过的播放时间计数?
-(MPRemoteCommandHandlerStatus)changedThumbSlider:(MPChangePlaybackPositionCommandEvent *)event {
// change position
CMTime seekingCM = CMTimeMakeWithSeconds(event.positionTime, 1000000);
[self.queuePlayer seekToTime:seekingCM];
return MPRemoteCommandHandlerStatusSuccess;
}
我在堆栈溢出中搜索其他问题,因此请尝试以下操作,但已停止播放时间。
-(MPRemoteCommandHandlerStatus)changedThumbSlider:(MPChangePlaybackPositionCommandEvent *)event {
// change position
CMTime seekingCM = CMTimeMakeWithSeconds(event.positionTime, 1000000);
[self.queuePlayer seekToTime:seekingCM];
// update now playing info center
__strong NSMutableDictionary *songInfo = nil;
__weak MPNowPlayingInfoCenter *nowPlayingInforCenter = nil;
nowPlayingInforCenter = [MPNowPlayingInfoCenter defaultCenter];
songInfo = [nowPlayingInforCenter.nowPlayingInfo mutableCopy];
Float64 duration = CMTimeGetSeconds(self.queuePlayer.currentItem.duration);
Float64 elapsed = CMTimeGetSeconds(self.queuePlayer.currentTime);
[songInfo setObject:[NSNumber numberWithFloat:1.0f]
forKey:MPNowPlayingInfoPropertyPlaybackRate];
[songInfo setObject:[NSNumber numberWithDouble:duration]
forKey:MPMediaItemPropertyPlaybackDuration];
[songInfo setObject:[NSNumber numberWithDouble:elapsed]
forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime];
[nowPlayingInforCenter setNowPlayingInfo:songInfo];
return MPRemoteCommandHandlerStatusSuccess;
}