私のアプリでは、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をリリースできますか?
音が変わると「play」メソッドを呼び出しますが、このメソッドは毎回新しいAVAudioPlayerを割り当てます
知っている
- (void) audioPlayerDidFinishPlaying: (AVAudioPlayer *) player
successfully: (BOOL) flag {
しかし、このデリゲートメソッド内でサウンドIDを解放する方法がわかりません。これは、soundId内で解放すると、アプリを使用して数分後にアプリがクラッシュし、このメッセージ「shm_openfailed: "AppleAudioQueue"」がクラッシュするためです。
助けてください...ありがとう