0
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if(actionSheet.tag == 2) {
if(buttonIndex != actionSheet.cancelButtonIndex) {
NSString *s = [actionSheet buttonTitleAtIndex:buttonIndex];
NSString *soundFile = [[NSBundle mainBundle] pathForResource:s ofType:@"m4a"];
NSURL *soundUrl = [NSURL fileURLWithPath:soundFile];
AVAudioPlayer *player = [[AVAudioPlayer alloc]initWithContentsOfURL:soundUrl error:nil];
player.numberOfLoops = 0;
[player play];
}
}
}
播放声音当我把在[player play];
断点,单步执行,iPhone正在播放的声音。没有断点就不会播放声音。为什么发生这种情况?需要帮助的uiactionsheet自来水
因为只要方法超出范围,您的播放器就会被释放(因为您将其作为局部变量创建)。为玩家创造一个强大的财产,它会正常工作。 – rdelmar
@rdelmar感谢您的回复,请将其发布为答案,以便我可以投票并选择正确的答案。 –