Xcode 6 个音频问题

Xcode 6 audio problems

最近我将 Xcode 从 5 版本更新到 6.4 版本,模拟器没有任何声音,但有一些错误消息。最简单的代码不 运行 好,应用程序本身在模拟器中启动但没有音频,问题可能出在某些设置中,因为我之前的所有代码和程序都 运行 好。我使用的是 b运行d new mac mini,所以我从一个不同的旧代码中导入了这些代码。

如果有人遇到这样的问题,请帮助我!

错误是这样的:

2015-08-01 09:03:56.730 Testbutton[496:11659] 09:03:56.730 ERROR: 98: Error '!obj' trying to fetch default input device's sample rate
2015-08-01 09:03:56.731 Testbutton[496:11659] 09:03:56.731 ERROR: 100: Error getting audio input device sample rate: '!obj'
2015-08-01 09:03:56.731 Testbutton[496:11659] 09:03:56.731 WARNING: 230: The input device is 0x0; '(null)'
2015-08-01 09:03:56.731 Testbutton[496:11659] 09:03:56.731 WARNING: 234: The output device is 0x26; 'AppleHDAEngineOutput:1B,0,1,2:0'
2015-08-01 09:03:56.732 Testbutton[496:11659] 09:03:56.732 ERROR: 296: error '!obj'
2015-08-01 09:03:56.732 Testbutton[496:11659] 09:03:56.732 ERROR: 113: * * * NULL AQIONode object
2015-08-01 09:03:56.732 Testbutton[496:11403] 09:03:56.732 ERROR: 296: error -66680
2015-08-01 09:03:56.732 Testbutton[496:11403] 09:03:56.732 ERROR: >aq> 1595: failed (-66680); will stop (11025/0 frames)
2015-08-01 09:03:56.736 Testbutton[496:11659] 09:03:56.736 ERROR: 703: Can't make UISound Renderer

代码是这样的:

//  ViewController.m
//  Testbutton

#import "ViewController.h"

@interface ViewController ()
{
    AVAudioPlayer *_audioPlayer;
}
@end

@implementation ViewController



- (void)viewDidLoad
{
    [super viewDidLoad];

    // Construct URL to sound file
    NSString *path = [NSString stringWithFormat:@"%@/horn.wav",     [[NSBundle mainBundle] resourcePath]];
    NSURL *soundUrl = [NSURL fileURLWithPath:path];

    // Create audio player object and initialize with URL to sound
_audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil];
}

- (IBAction)buttonPressed:(id)sender {

    [_audioPlayer play];
}

- (void)dealloc {
    [audioPlayerPointer release];
    [super dealloc];
}

@end

还有一个头文件:

#import <UIKit/UIKit.h>

#import <AVFoundation/AVFoundation.h>

@interface ViewController : UIViewController

{

    AVAudioPlayer* audioPlayerPointer;

}

- (IBAction)buttonPressed:(id)sender;


@end

AVAudioPlayer 需要有效的输入和输出才能进行自我设置。这在真实设备(内置这些东西)上不是问题,但在 MacMini 上没有内置麦克风的模拟器中是个问题。

如果您有麦克风,请尝试将其插入 MacMini 上的 "line in" 端口(我发现了这个可能的解决方案 in the comments of the answer to this very related question)。确保 select "line-in" 也作为系统偏好设置中的输入。