问题描述
我正在尝试测试 AVAudioEngine,观看了有关它的 WWDC 会议,并按照书中的所有内容尝试播放一个简单的文件。
尽管一切都与我发现的样本(WWDC 和其他一些地方)完全相同,尽管一切看起来都很好(没有错误,似乎正在运行),但我没有声音输出。
代码如下:
NSError *error = Nil;
[AVAudioSession.sharedInstance setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error: &error];
[AVAudioSession.sharedInstance setActive:YES error:&error];
AVAudioEngine *engine = [[AVAudioEngine alloc] init];
AVAudioPlayerNode *player = [[AVAudioPlayerNode alloc] init];
[engine attachNode:player];
NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"piano" withExtension:@"wav"];
AVAudioFile *file = [[AVAudioFile alloc] initForReading:fileURL error:&error];
AVAudioMixerNode *mainMixer = [engine mainMixerNode];
AVAudioOutputNode *outputNode = engine.outputNode;
[engine connect:player to:mainMixer format:file.processingFormat];
[engine connect:engine.mainMixerNode to:outputNode format:nil];
[engine prepare];
if (!engine.isRunning) {
if (![engine startAndReturnError:&error]) {
//TODO
}
}
[player scheduleFile:file atTime:nil completionHandler:nil];
[player play];
NSLog(@"Engine description: %@",[engine description]);
这是日志调用的输出:
Engine description:
________ GraphDescription ________
AVAudioEngineGraph 0x10100d820: initialized = 1,running = 1,number of nodes = 3
******** output chain ********
node 0x28388d200 {'auou' 'rioc' 'appl'},'I'
inputs = 1
(bus0,en1) <- (bus0) 0x2838a0880,{'aumx' 'mcmx' 'appl'},[ 2 ch,44100 Hz,'lpcm' (0x00000029) 32-bit little-endian float,deinterleaved]
node 0x2838a0880 {'aumx' 'mcmx' 'appl'},en1) <- (bus0) 0x282a8df00,{'augn' 'sspl' 'appl'},deinterleaved]
outputs = 1
(bus0,en1) -> (bus0) 0x28388d200,{'auou' 'rioc' 'appl'},deinterleaved]
node 0x282a8df00 {'augn' 'sspl' 'appl'},'I'
outputs = 1
(bus0,en1) -> (bus0) 0x2838a0880,deinterleaved]
______________________________________
我不知道如何诊断这个问题,也找不到任何错误或无法正常工作的原因。
有什么想法吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)