我在使用 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 然后调用不起作用的播放。
//Stop the player and restart it
if (player.playing) {
NSLog(@"Reset sound: %@", selectedSound);
player.currentTime = 0;
[player play];
} else {
NSLog(@"playSound: %@", selectedSound);
[player play];
}