gpt4 book ai didi

ios - 如何为 AVAudioEngine 设置完成处理程序

转载 作者:行者123 更新时间:2023-11-29 11:46:53 25 4
gpt4 key购买 nike

我正在使用这个方法来播放音频文件;

-(void)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];

如果没有成功,我该如何调用完成处理程序?

最佳答案

您需要使用 GCD block ,而不是方法,作为 completionHandler 参数:

[node scheduleFile:audioFile atTime:nil completionHandler:^{

// Your "stopTalking" code goes here...

}];

关于ios - 如何为 AVAudioEngine 设置完成处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43256549/

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