首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >强制内置麦克风超过蓝牙耳机的麦克风?

强制内置麦克风超过蓝牙耳机的麦克风?
EN

Stack Overflow用户
提问于 2016-01-27 14:57:38
回答 1查看 417关注 0票数 0

我想使用设备上的内置麦克风进行输入,使用蓝牙耳机进行输出。我的会话类别是而且必须是AVAudioSessionCategoryPlayAndRecord。我试过使用setPreferredInput:连接内置麦克风,但它也会将输出切换到设备的扬声器。

我见过this (特别是评论),在那里他们提到了这是可能的。

EN

回答 1

Stack Overflow用户

发布于 2016-01-27 15:09:13

你可以使用下面的代码

代码语言:javascript
复制
// create and set up the audio session

AVAudioSession* audioSession = [AVAudioSession sharedInstance];

[audioSession setDelegate:self];

[audioSession setCategory: AVAudioSessionCategoryPlayAndRecord error: nil];

[audioSession setActive: YES error: nil];


// set up for bluetooth microphone input

UInt32 allowBluetoothInput = 1;

OSStatus stat = AudioSessionSetProperty (
                         kAudioSessionProperty_OverrideCategoryEnableBluetoothInput,
                         sizeof (allowBluetoothInput),
                         &allowBluetoothInput
                        );

NSLog(@"status = %x", stat);    // problem if this is not zero

// check the audio route

UInt32 size = sizeof(CFStringRef);

CFStringRef route;

OSStatus result = AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &size, &route);
NSLog(@"route = %@", route);  

// if bluetooth headset connected, should be "HeadsetBT"

// if not connected, will be "ReceiverAndMicrophone"

// now, play a quick sound we put in the bundle (bomb.wav)

CFBundleRef mainBundle = CFBundleGetMainBundle();

CFURLRef        soundFileURLRef;

SystemSoundID   soundFileObject;

soundFileURLRef  = CFBundleCopyResourceURL (mainBundle,CFSTR ("bomb"),CFSTR ("wav"),NULL);

AudioServicesCreateSystemSoundID (soundFileURLRef,&soundFileObject);

AudioServicesPlaySystemSound (soundFileObject); 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35030646

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档