AVAudioPlayer stop a sound and play it from the beginning

后端 未结 3 1343
旧时难觅i
旧时难觅i 2021-02-05 03:25

I used the AVAudioPlayer to play a 10 sec wav file and it works fine. Now I what to stop the wav at the 4th sec and then play it again from the very 1st sec.

Here is th

3条回答
  •  逝去的感伤
    2021-02-05 03:31

    Apple's AVAudioPlayer class reference says:

    The stop method does not reset the value of the currentTime property to 0. In other words, if you call stop during playback and then call play, playback resumes at the point where it left off.

    So you should be able to restart it with:

    [ahhhhhSound stop];
    ahhhhhSound.currentTime = 0;
    [ahhhhhSound play];
    

提交回复
热议问题