ios addPeriodicTimeObserverForInterval获取音频播放进度循环

[_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)];
        
    }];

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值