dub*_*eat 6 iphone volume objective-c avaudioplayer
是否有人可以通过教程链接向AVAudioPlayer添加播放进度条?
我在这个网站和谷歌上广泛搜索无济于事
dub*_*eat 19
我想通了,它不是太糟糕.
只需在计时器中更新它
playbackTimer=[NSTimer scheduledTimerWithTimeInterval:0.5
target:self
selector:@selector(myMethod:)
userInfo:nil
repeats:YES];
}
-(void)myMethod:(NSTimer*)timer {
float total=audioPlayer.duration;
float f=audioPlayer.currentTime / total;
NSString *str = [NSString stringWithFormat:@"%f", f];
playbackProgress.progress=f;
NSLog(str);
}
Run Code Online (Sandbox Code Playgroud)
的CADisplayLink类,它会自动调用一个方法,你只要在屏幕重绘发生定义
Timer 不提供精确触发,并且可能比请求的更新更早或更晚漂移,并且也不知道屏幕重绘,因此可以在刚刚发生屏幕重绘后的 10 毫秒内愉快地触发。
let displayLink = CADisplayLink(target: self,
selector: #selector(update))
displayLink.add(to: .current, forMode: .common)
@objc func update() {
let currentTime = avAudioPlayer.currentTime
let totalTime = avAudioPlayer.duration
let progress = currentTime / totalTime
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9180 次 |
| 最近记录: |