我有这样的值更改事件处理程序:
I've got valuechanged event handler like that:
-(void)scrub:(id)sender { if(self.audioPlayer.playing) { self.audioPlayer.pause; self.audioPlayer.currentTime=self.scrubber.value; self.audioPlayer.play; } }为什么不倒带发生?我应该添加什么?谢谢! 另外,如何在标签中显示当前时间?
Why doesn't rewind happen? what should I add? thanks! Moreover, how to display current time in a label?
推荐答案要设置时间,您可以执行以下操作:
To set the time, you can do:
[audioPlayer setTime:self.scrubber.value];但是,您需要验证它实际上是一个数字.您还需要确保在适当的时间使用您正在使用的文件.我不知道您使用的是哪种洗涤器.如果setCurrentTime不起作用,则说明洗涤器存在一些问题.
However, you need to verify that that is actually a number. You also need to make sure it has an appropriate time for the file you are using. I don't know what kind of scrubber you are using. If setCurrentTime doesn't work, there is some problem with your scrubber.
如果您使用的是UISlider,则可以执行以下操作来设置时间:
If you are using a UISlider, you can do something like this to set the time:
double value = progressSlider.value; double newSeekTime = (value / 100.0) * audioPlayer.duration; [audioPlayer setCurrentTime:(int)newSeekTime];要获取时间,只需执行audioPlayer.currentTime.这是一个NSTimeInterval,仅是一个两倍.要显示时间,您可以执行以下操作:
To get the time, you simply do audioPlayer.currentTime. This is an NSTimeInterval, which is just a double. To display the time, you can do:
NSString *positionString = [NSString stringWithFormat:@"%.2d:%.2d / %.2d:%.2d", (NSInteger)progress/60, (NSInteger)progress%60, (NSInteger)duration/60, (NSInteger)duration%60]; myLabel.text = positionString;更多推荐
AVAudioplayer的简单倒带
发布评论