- (void)initAVCaptureSession {
[self setupVideo];
[self setupAudio];
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker | AVAudioSessionCategoryOptionAllowBluetooth error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
}
- (void)setupAudio {
NSError *error = nil;
self.audioInput = [[AVCaptureDeviceInput alloc] initWithDevice:[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio] error:&error];
if (error) {
return;
}
if ([self.session canAddInput:self.audioInput]) {
[self.session addInput:self.audioInput];
}
self.audioOutput = [[AVCaptureAudioDataOutput alloc] init];
dispatch_queue_t audioQueue = dispatch_queue_create("com.haha.com", DISPATCH_QUEUE_SERIAL);
[self.audioOutput setSampleBufferDelegate:self queue:audioQueue];
if([self.session canAddOutput:self.audioOutput]) {
[self.session addOutput:self.audioOutput];
}
}
......
Запись видео и воспроизведение звука с помощью AVAudioPlayer. Когда устройство подключено к Bluetooth, телефон не воспроизводит звук через Bluetooth, но продолжает использовать динамики телефона.
После инициализации всех данных, когда я не вызываю setupaudio method, the audio can be played through the Bluetooth speaker. When I call
setupaudio`, звук будет воспроизводиться только на динамике телефона. Кто-нибудь знает почему?