我在使用AVAudioPlayer时遇到了问题,我想在播放器正在播放时重置它并再次播放。
我尝试了以下方法但没有成功:
声音只播放一次,但第二次选择按钮时它就停止了声音,第三次又开始播放声音。
//Stop the player and restart it
if (player.playing) {
NSLog(@"Reset sound: %@", selectedSound);
[player stop];
[player play];
} else {
NSLog(@"playSound: %@", selectedSound);
[player play];
}
我还尝试使用 player.currentTime = 0 重置播放器,但没有成功,我还尝试重置 currentTime = 0 然后调用 play,也没有成功。
//Stop the player and restart it
if (player.playing) {
NSLog(@"Reset sound: %@", selectedSound);
player.currentTime = 0;
[player play];
} else {
NSLog(@"playSound: %@", selectedSound);
[player play];
}