Unable to Implement Forward Action in AVAudioplayer

前端 未结 2 1852
南方客
南方客 2021-01-15 08:28

I am using AVAudioplayer to play some audio files. I have some controls like forward and rewind.

Rewind is working properly but forward is not.

- (vo         


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-01-15 09:14

    you might have done the property declaration of AVAudioPlayer *player; in the h file and also synthesised it. Now for forward, just do,

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

    do 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 the better way, also for rewind compare to 0 instead of duration

提交回复
热议问题