Ios AVAudioPlayer,很多声音
在我的应用程序中,我使用AVAudioPlayer播放一些mp3。我的代码是:Ios AVAudioPlayer,很多声音,ios,memory-management,avaudioplayer,Ios,Memory Management,Avaudioplayer,在我的应用程序中,我使用AVAudioPlayer播放一些mp3。我的代码是: - (void) play{ NSString *path = [NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath], [arraysound objectAtIndex:appDelegate.indexSound]];
- (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种声音要演奏;我使用everytime soundID播放我的声音
例如我有sound1.mp3,sound2.mp3,sound3.mp3
如何释放我的声音ID
当我的声音改变时,我调用play方法,但这种方法每次都会分配一个新的AVAudioPlayer
我知道
- (void) audioPlayerDidFinishPlaying: (AVAudioPlayer *) player
successfully: (BOOL) flag {
但我不明白如何在这个委托方法中释放我的sound id,因为如果我在sound id中释放,我的应用程序就会崩溃
在我使用我的应用程序几分钟后,我崩溃了,这条消息shm_open failed:Apple Audio Queue
请帮助我…谢谢您不想在委托方法中释放soundID。你想释放玩家。从您的代码判断,soundID是ivar。调用委托时,soundID可能已设置为另一个值。但是player参数将是刚刚播放完的AVAudioPlayer。您是在调用委托方法的地方等待每个声音结束,还是手动更改它们?