AVAudioplayer的简单倒带 [英] Simple Rewind for AVAudioplayer

查看:82
本文介绍了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的简单倒带的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆