1

我正在尝试使用DIYCam录制视频并将蓝牙耳机的音频路由设置为音频输入,但似乎路由不起作用。据我了解,我只需要将音频输入路由到我的蓝牙耳机,我不需要对 DIYCam 进行任何更改,对吗?这是我的代码:

当视图加载时,我创建了 DIYCam 实例:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    [self.navigationController setNavigationBarHidden:YES];

    self.camera = [[DIYCam alloc] initWithFrame:self.view.bounds];
    self.camera.delegate = self;
    [self.camera setupWithOptions:nil]; // Check DIYAV.h for options
    [self.camera setCamMode:DIYAVModeVideo];
    [self.view addSubview:self.camera];
    [self.view sendSubviewToBack:self.camera];

    if( self.bluetoothInput ) {
        [self setBluetoothAudioInput];
    }
}

这是我的蓝牙路由功能:

- (void)setBluetoothAudioInput
{
    // create and set up the audio session
    AVAudioSession* audioSession = [AVAudioSession sharedInstance];
    [audioSession setDelegate:self];
    [audioSession setCategory:AVAudioSessionCategoryRecord error:nil];
    [audioSession setActive:YES error:nil];

    // set up for bluetooth microphone input
    UInt32 allowBluetoothInput = 1;
    OSStatus stat = AudioSessionSetProperty (
                                             kAudioSessionProperty_OverrideCategoryEnableBluetoothInput,
                                             sizeof (allowBluetoothInput),
                                             &allowBluetoothInput
                                             );
}

这些是用于启动和停止的 IBAction:

- (IBAction)startRecording:(id)sender
{
    [self.camera startSession];
    [self.camera captureVideoStart];
}

- (IBAction)stopRecording:(id)sender
{
    [self.camera captureVideoStop];
    [self.camera stopSession];
}
4

2 回答 2

0

我相信您需要让用户手动设置用于音频的输入设备。我刚刚遇到了类似的问题,并使用了 MPVolumeView,将 showVolumeSlider 布尔值设置为 NO。这提供了一个可点击的按钮来从可用的列表中设置所需的输入。

签出: 从蓝牙输出到线路输出或扬声器的 AudioSession 输入

于 2013-06-18T18:55:54.123 回答
0

尝试这个:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:nil];
于 2015-11-02T04:29:15.473 回答