[_player addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(1, 1) queue:NULL usingBlock:^(CMTime time) {
//进度 当前时间/总时间
wSelf.progress.progress =CMTimeGetSeconds(wSelf.player.currentItem.currentTime)/CMTimeGetSeconds(wSelf.player.currentItem.duration);
NSLog(@"per:%f-%f",CMTimeGetSeconds(wSelf.player.currentItem.currentTime),CMTimeGetSeconds(wSelf.player.currentItem.duration));
if ( wSelf.progress.progress==1) {
[wSelf.kPlayerItem seekToTime:kCMTimeZero completionHandler:^(BOOL finished) {
//主要是这里,需要加上判断,
//当播放进度为单位“1”,说明播放已完毕,就需要将进度设置为“0”既开始状态,但是系统另一个方法,没有这个回调finish参数,导致无法判断是否设置为“0”已经完成,就饿能造成,音频实际上还没设置为进度为“0”状态,又走了这个回调,又“play”,看起来就像是循环
if(finished){
//解决方法,就是判断finish==yes,说明已经设置为”0“开始状态完毕,才能再次“play”播放器播放
[wSelf.player play];
}
}];
}
wSelf.label.text = [NSString stringWithFormat:@"%.2f秒|%.2f秒",CMTimeGetSeconds(wSelf.player.currentItem.currentTime),CMTimeGetSeconds(wSelf.player.currentItem.duration)];
}];