Objective c AudioQueue |在AudioQueue运行时更改音频设备
我使用音频队列在OSX | Mac上播放和录制,并有一个用例,Objective c AudioQueue |在AudioQueue运行时更改音频设备,objective-c,macos,audio,core-audio,audioqueue,Objective C,Macos,Audio,Core Audio,Audioqueue,我使用音频队列在OSX | Mac上播放和录制,并有一个用例, 这类似于,当音频队列正在运行以进行播放或录制时,用户可以更改音频设备(输入和输出) 这就是我到目前为止所做的 OSStatus result = noErr; // get the device list AudioObjectPropertyAddress thePropertyAddress = { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyS
这类似于,当音频队列正在运行以进行播放或录制时,用户可以更改音频设备(输入和输出) 这就是我到目前为止所做的
OSStatus result = noErr;
// get the device list
AudioObjectPropertyAddress thePropertyAddress = { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster };
UInt32 thePropSize;
CFStringRef theDeviceName;
// get the device name
thePropSize = sizeof(CFStringRef);
thePropertyAddress.mSelector = kAudioObjectPropertyName;
thePropertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
thePropertyAddress.mElement = kAudioObjectPropertyElementMaster;
// get the name of the device
result = AudioObjectGetPropertyData( (AudioObjectID)input,
&thePropertyAddress, 0, NULL, &thePropSize, &theDeviceName);
if ( result != noErr){
log("Error while getting property");
return;
}
// get the uid of the device
CFStringRef theDeviceUID;
thePropertyAddress.mSelector = kAudioDevicePropertyDeviceUID;
result = AudioObjectGetPropertyData( (AudioObjectID)input,
&thePropertyAddress, 0, NULL, &thePropSize, &theDeviceUID);
try{
XThrowIfError(AudioQueueSetProperty(mQueue,kAudioQueueProperty_CurrentDevice,&theDeviceUID, sizeof(CFStringRef)),"set input device");
}
catch (CAXException e) {
char buf[256];
fprintf(stderr, "Error: %s (%s)\n", e.mOperation, e.FormatError(buf));
}
但它抛出了一个异常kaudioqueerr_InvalidRunState,说它不能在队列运行时执行
有没有其他方法可以达到同样的效果 不幸的是,没有其他方法可以实现这一点(AudioQueue的函数太少)。您需要首先停止音频队列,然后更改其属性,最后再次启动它