iOS - 如何使用蓝牙耳机录制视频作为音频输入?

时间:2013-05-29 20:27:13

标签: iphone ios bluetooth avfoundation video-recording

我正在尝试使用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];
}

2 个答案:

答案 0 :(得分:0)

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

退房: AudioSession input from bluetooth output to line out or speaker

答案 1 :(得分:0)

试试这个:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:nil];