gpt4 book ai didi

xcode - AVAudioPlayer 在播放前释放?

转载 作者:行者123 更新时间:2023-12-03 02:22:56 25 4
gpt4 key购买 nike

我正在制作 soundboard app 和我用这段代码玩mp3文件:

-(IBAction)playSound 
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"mysound" ofType:@"mp3"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];
[theAudio release];
}

当我包含 [theAudio release];声音不播放。如果我把它拿出来,它会播放,但我不想出现内存泄漏。我怎样才能解决这个问题?

如果您可以包含我需要添加的任何代码,那将非常有帮助。我是编程新手(除了我在学校用过的 TrueBasic),所以我不熟悉 Objective-C。

最佳答案

等待音频通过委托(delegate)完成以释放音频。我相信如果您搜索,网站上有许多与此完全相同的帖子,它们将具有特定的委托(delegate)代码。

关于xcode - AVAudioPlayer 在播放前释放?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9426456/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com