Dou*_*kem 16 iphone audio core-audio avaudioplayer
我在使用AVAudioPlayer时遇到问题,我想重置一个播放器,如果它正在播放并重新播放.
我试着以下没有运气:
声音播放一次,但第二次我选择按钮停止声音,第三次再次启动声音.
//Stop the player and restart it
if (player.playing) {
NSLog(@"Reset sound: %@", selectedSound);
[player stop];
[player play];
} else {
NSLog(@"playSound: %@", selectedSound);
[player play];
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过使用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];
}
Run Code Online (Sandbox Code Playgroud)
Jon*_*ast 37
根据您的情况,我会尝试以下方法
//Pause the player and restart it
if (player.playing) {
NSLog(@"Reset sound: %@", selectedSound);
[player pause];
}
player.currentTime = 0;
[player play];
Run Code Online (Sandbox Code Playgroud)
如果你要立即再次播放声音,我会建议暂停而不是停止.呼叫停止"停止播放并取消播放所需的设置."