1
我正在使用此方法播放音頻文件;如何爲AVAudioEngine設置完成處理程序
- (空)playOnMainThread:(ID)參數
{
[self playAudio];
AVAudioEngine *engine = [[AVAudioEngine alloc] init];
AVAudioPlayerNode *node = [[AVAudioPlayerNode alloc] init];
[engine attachNode:node];
AVAudioUnitTimePitch *pitch = [[AVAudioUnitTimePitch alloc] init];
pitch.pitch = 100;
pitch.rate = 2;
[engine attachNode:pitch];
AVAudioMixerNode *mixerNode = engine.mainMixerNode;
[engine connect:node to:pitch format:[mixerNode outputFormatForBus:0]];
[engine connect:pitch to:mixerNode format:[mixerNode outputFormatForBus:0]];
AVAudioFile *audioFile = [[AVAudioFile alloc] initForReading:recorder.url error:&error];
if (error)
NSLog(@"AVAudioPlayer error %@, %@", error, [error userInfo]);
if (audioFile != nil) {
[node scheduleFile:audioFile atTime:nil completionHandler:nil];
[engine startAndReturnError:nil];
[node play];
}
}
但我需要設置一個completionhandler,這就是我曾嘗試;
-(void)stopTalking:(AVAudioNodeCompletionHandler)handler
//-(void)stopTalking
{
isPlaying = NO;
[self unschedule:@selector(RepeatSpeackAction)];
[self schedule:@selector(StartGAmeCall)];
[stand setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"Turn1.png"]];
if(video==true) {
cases=1;
[self addaudiotoDict];
}
}
我試圖用這樣的方式調用它;
[node scheduleFile:audioFile atTime:nil completionHandler:stopTalking];
沒有成功,我該如何調用完成處理程序?
非常感謝你 - 完美的工作! – Hypergater