这是最简单的 AVAudioPlayer 代码,只是无法播放任何内容。没有错误,控制台中什么都没有,文件肯定被找到,就好像我将 URL 字符串更改为不存在的东西一样,我确实遇到了崩溃。我在这里做错了什么?我在有和没有委托的情况下,以及有和没有prepareToPlay的情况下都试过了,但我什么也做不了。我也尝试过各种声音文件。真的把我的头发扯掉了!
@implementation ViewController
- (IBAction)playSound:(id)sender
{
NSURL *soundLocation = [[NSURL alloc] initWithString:@"Lot01.wav"];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundLocation error:nil];
[audioPlayer setDelegate:self];
[audioPlayer play];
}
@end