【问题标题】:AVAudioPlayer, a lot of soundsAVAudioPlayer,很多声音
【发布时间】:2012-04-23 23:26:28
【问题描述】:

在我的应用程序中,我使用 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”

请帮帮我...谢谢

【问题讨论】:

  • 您是在等待每个声音完成调用委托方法的位置,还是手动更改它们?

标签: ios memory-management avaudioplayer


【解决方案1】:

您不想在您的委托方法中释放soundID。你想释放player。从您的代码来看,soundID 是一个 ivar。当委托被调用时,soundID 可能已设置为另一个值。但是player参数会是刚刚播放完的AVAudioPlayer

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-22
    • 1970-01-01
    • 1970-01-01
    • 2015-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-20
    相关资源
    最近更新 更多