AVAudioPlayer重置当前播放声音,并从一开始就玩 [英] AVAudioPlayer resetting currently playing sound and playing it from beginning
问题描述
我使用AVAudioPlayer,我想重置一个球员,如果它当前正在播放,并让它再次发挥有一个问题。
我尝试没有运气以下内容:
声音播放一次但第二次我选择它停止声音按钮,第三次再次启动的声音响了起来。
//停止播放器并重新启动
如果(player.playing){
的NSLog(@复位声:%@,selectedSound);
[播放器停止]
[播放器播放];
}其他{
的NSLog(@playSound:%@,selectedSound);
[播放器播放];
}
我使用player.currentTime = 0,这表明将播放器复位,没有工作,我也尝试重置currentTime的= 0,然后调用播放,没有工作也尝试过。
//停止播放器并重新启动
如果(player.playing){
的NSLog(@复位声:%@,selectedSound);
player.currentTime = 0;
[播放器播放];
}其他{
的NSLog(@playSound:%@,selectedSound);
[播放器播放];
}
有关你的情况我想尝试以下
//暂停播放器并重新启动
如果(player.playing){
的NSLog(@复位声:%@,selectedSound);
[播放暂停]
}player.currentTime = 0;
[播放器播放];
如果你要立即再次播放声音,我会建议暂停而不是停止。呼吁停止停止播放,并撤消需要播放的设置。
I'm having an issue using AVAudioPlayer where I want to reset a player if it's currently playing and have it play again.
I try the following with no luck:
The sound plays once but then the second time i select the button it stops the sound, the third time starts the sound up again.
//Stop the player and restart it
if (player.playing) {
NSLog(@"Reset sound: %@", selectedSound);
[player stop];
[player play];
} else {
NSLog(@"playSound: %@", selectedSound);
[player play];
}
I've also tried using player.currentTime = 0 which indicates that would reset the player, that didn't work, I also tried resetting currentTime = 0 and then calling play that didn't work.
//Stop the player and restart it
if (player.playing) {
NSLog(@"Reset sound: %@", selectedSound);
player.currentTime = 0;
[player play];
} else {
NSLog(@"playSound: %@", selectedSound);
[player play];
}
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."
这篇关于AVAudioPlayer重置当前播放声音,并从一开始就玩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!