AVAudioPlayer 开始和暂停

来源:互联网 发布:csdn 算法岗面试 编辑:程序博客网 时间:2024/06/04 08:04

下面直接上代码

// 这个是定时器,定时更新播放进度-(NSTimer *)timer{    if (!_timer) {        _timer=[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(updateProgress) userInfo:nil repeats:true];    }    return _timer;}
// 播放音频-(void)play{    if (![self.audioPlayer isPlaying]) {        [self.audioPlayer play];        self.timer.fireDate=[NSDate distantPast];//恢复定时器    }}
// 暂停播放-(void)pause{    if ([self.audioPlayer isPlaying]) {        [self.audioPlayer pause];        self.timer.fireDate=[NSDate distantFuture];//暂停定时器,注意不能调用invalidate方法,此方法会取消,之后无法恢复            }}

原创粉丝点击