Unable to perform direct action in AVAudioplayer

I use AVAudioplayer to play some audio files. I have some controls, such as fast forward and fast reverse.

Rewinding works correctly, but not forward.

- (void)rewind
{
    AVAudioPlayer *player = _rewTimer.userInfo;
    player.currentTime-= SKIP_TIME;
    [_rewTimer invalidate];
    _rewTimer=nil;
    [self updateCurrentTime];
}

- (void)ffwd
{
    AVAudioPlayer *player = _ffwTimer.userInfo;
    player.currentTime-= SKIP_TIME;
    [player setCurrentTime:cTime];
    [_ffwTimer invalidate];
    _ffwTimer=nil;

    [self updateCurrentTime];
}

As soon as I press the forward button, the sound file starts playing from the very beginning.

I followed Apple's avTouch sample application.

+2
source share
2 answers

You may have made an announcement to the AVAudioPlayer * Player property; in the h file, and also synthesized it. Now for forwarding, just do

- (void)ffwd
{
    NSTimeInterval *time = [player currentTime];
    time+=SKIP_TIME;
    [player setCurrentTime:time];    

}

similarly for rewind +

OR

 - (void)ffwd{
    NSTimeInterval time = avPlayer.currentTime;
 time+=SKIP_TIME;
    if (time > avPLayer.duration)
    {
       //nothing to do

    }
    else
        [player setCurrentTime:time];
    }

this one seems to be the best way, and also to rewind instead of 0 instead of duration

+2

, cTime , , . , currentTime .

, , . , , . - , .

0

All Articles