开发者

Simple Rewind for AVAudioplayer

开发者 https://www.devze.com 2023-03-30 04:28 出处:网络
I\'ve got valuechanged event handler like that: -(void)scrub:(id)sender { if(self.audioPlayer开发者_开发百科.playing)

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];

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.

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];

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消