0
私はバッファを介してファイルを再生し、それを停止するこの単純なプログラムでメモリを解放する方法を知っています。簡単なavaudioengineプログラムでメモリを解放しますか?
-(void)setupAudioOne
{
NSError *error;
BOOL success = NO;
_player = [[AVAudioPlayerNode alloc] init];
NSURL *hiphopOneURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Hip Hop 1" ofType:@"caf"]];
AVAudioFile *hiphopOneFile = [[AVAudioFile alloc] initForReading:hiphopOneURL error:&error];
_playerLoopBuffer = [[AVAudioPCMBuffer alloc] initWithPCMFormat:[hiphopOneFile processingFormat] frameCapacity:(AVAudioFrameCount)[hiphopOneFile length]];
success = [hiphopOneFile readIntoBuffer:_playerLoopBuffer error:&error];
_engine = [[AVAudioEngine alloc] init];
[_engine attachNode:_player];
AVAudioMixerNode *mainMixer = [_engine mainMixerNode];
AVAudioFormat *stereoFormat = [[AVAudioFormat alloc] initStandardFormatWithSampleRate:44100 channels:2];
[_engine connect:_player to:mainMixer fromBus:0 toBus:0 format:stereoFormat];
[self startEngine];
}
上記は、エンジンとプレーヤーノードの一般的な設定です。 その後、我々は再生ボタンを持つプレイヤーを実装:
- (IBAction)play:(id)sender {
if (!self.playerIsPlaying)
{
[self setupAudioOne];
[_player scheduleBuffer:_playerLoopBuffer atTime:nil options:AVAudioPlayerNodeBufferLoops completionHandler:nil];
[_player play];
}
}
をそして最後に、我々は、停止ボタンを持つプレーヤーを停止します。
- (IBAction)stopHipHopOne:(id)sender {
if (self.playerIsPlaying) {
[_player stop];
}
playerIsPlayingは_playerが再生されているかどうかを判断するだけのシンプルなBOOLです。
基本的に私の質問は、このプログラムが書かれているときに停止ボタンを押すとメモリが解放されないということです。 確かに、エンジンとプレーヤーが使用しているメモリを解放する停止ボタンに追加できる単純なコード行がありますか?
どのような考えですか?
あなたのアプリはARCを使用していますか? –
はい、それはARCを使用しています。 –