Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c AudioQueue |在AudioQueue运行时更改音频设备_Objective C_Macos_Audio_Core Audio_Audioqueue - Fatal编程技术网

Objective c AudioQueue |在AudioQueue运行时更改音频设备

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

我使用音频队列在OSX | Mac上播放和录制,并有一个用例,
这类似于,当音频队列正在运行以进行播放或录制时,用户可以更改音频设备(输入和输出)

这就是我到目前为止所做的

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的函数太少)。您需要首先停止音频队列,然后更改其属性,最后再次启动它