ios AudioUnit bluetooth 录音 播放 实现
因为拍摄短视频的时候有时候手机离主人比较远的时候,这样录音效果就不好了, 为了方便记录声音,则最好的方式就是使用蓝牙耳机,但是ios关于蓝牙耳机的使用特别少,以下是我总结的内容。
#import "XYRecorder.h"
#import <AVFoundation/AVFoundation.h>
#define INPUT_BUS 1
#define OUTPUT_BUS 0
AudioUnit audioUnit;
AudioBufferList *buffList;
@implementation XYRecorder
#pragma mark - init
- (instancetype)init {
self = [super init];
if (self) {
AudioUnitInitialize(audioUnit);
[self initRemoteIO];
}
return self;
}
- (void)initRemoteIO {
[self initAudioSession];
[self initBuffer];
[self initAudioComponent];
[self initFormat];
[self initAudioProperty];
[self initRecordeCallback];
[self initPlayCallback];
}
- (void)initAudioSession {
NSError *error;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:&error];
[audioSession setPreferredSampleRate:44100 error:&error];
[audioSession se