AVAudioPlayer resetting currently playing sound and playing it from beginning
For your situation I would try the following
//Pause the player and restart it
if (player.playing) {
NSLog(@"Reset sound: %@", selectedSound);
[player pause];
}
player.currentTime = 0;
[player play];
If you are going to immediately play the sound again, I would suggest pause instead of stop. Calling stop "Stops playback and undoes the setup needed for playback."
Swift example:
player.currentTime = 0.0;
As indicated, if you want the sound to play again, you should avoid disabling the AVAudioPlayer instance with a stop but rather, just issue a reset of the position where it is playing. So, don't use stop() or pause() but as Plumenator mentioned, just issue .currentTime=0. So in your case, you would simply do:
if (player.isPlaying) {
player.currentTime = 0
} else {
player.play()
}