AVAudioplayer的简单倒带

编程入门 行业动态 更新时间:2024-10-24 08:20:02
本文介绍了AVAudioplayer的简单倒带的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有这样的值更改事件处理程序:

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的简单倒带

本文发布于:2023-07-11 09:12:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1093538.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:简单   AVAudioplayer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!