在我的应用程序中,我使用AVAudioPlayer播放一些mp3。我的代码是:
- (void) play{
NSString *path = [NSString stringWithFormat:@"%@/%@",
[[NSBundle mainBundle] resourcePath],
[arraysound objectAtIndex:appDelegate.indexSound]];
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
soundID = [[AVAudioPlayer alloc] initWithContentsOfURL:filePath error:nil];
soundID.delegate = self;
[soundID prepareToPlay];
[soundID play];
}
但我有40种声音可以播放;我每次使用soundID来播放我的声音
例子我有sound1.mp3,sound2.mp3,sound3.mp3 ......
我如何发布我的soundId?
当我的声音改变时,我称之为“播放”方法,但此方法每次都会分配一个新的AVAudioPlayer
我知道
- (void) audioPlayerDidFinishPlaying: (AVAudioPlayer *) player
successfully: (BOOL) flag {
但是我不明白如何在这个委托方法中释放我的声音id,因为如果我在soundId中释放我的应用程序崩溃 几分钟之后,我使用我的应用程序崩溃了这条消息“shm_open failed:”Apple Audio Queue“
请帮帮我......谢谢
答案 0 :(得分:0)
您不希望在委托方法中发布soundID
。您想要发布player
。从你的代码来看,soundID
是一个ivar。调用委托时,soundID
可能已设置为其他值。但player
参数将是刚刚播放完毕的AVAudioPlayer
。