问题描述
我一直在使用Xamarin.Mac中的macOS CoreAudio API。我需要的许多方法都没有绑定。在此post
的帮助下,我已经能够成功使用本机AudioObjectGetPropertyData
方法
我尝试使用相同的方法来绑定AudioHardwareCreateAggregateDevice
。
[DllImport(ObjCRuntime.Constants.AudioUnitLibrary)]
static extern uint AudioHardwareCreateAggregateDevice(
ref IntPtr inDescription,out uint outdeviceid
);
我已经在Xcode游乐场中测试了该代码的快速版本。效果很好。
func createMultIoUtputAudioDevice(masterDeviceUID: CFString,multIoUtUID: String) -> (Osstatus,Audiodeviceid) {
let desc: [String : Any] = [
kAudioAggregateDeviceNameKey: "My Multi-Output (NS 2)",kAudioAggregateDeviceUIDKey: multIoUtUID,kAudioAggregateDeviceSubDeviceListKey: [[kAudioSubDeviceUIDKey: masterDeviceUID]],kAudioAggregateDeviceMasterSubDeviceKey: masterDeviceUID,kAudioAggregateDeviceIsstackedKey: 1,]
var aggregateDevice: Audiodeviceid = 0
return (AudioHardwareCreateAggregateDevice(desc as NSDictionary,&aggregateDevice),aggregateDevice)
}
因此,在C#代码中,我用字符串值重新创建了枚举,并尝试为AudioHardwareCreateAggregateDevice
方法复制输入参数。代码可以编译,但是在我调用该方法时崩溃。
public static uint CreateMultIoUtputAudioDevice(string masterDeviceUID,string multIoUtUID)
{
var devices = new NSDictionary(kAudioSubDeviceUIDKey,masterDeviceUID);
var dictionary = new NSDictionary(
kAudioAggregateDeviceNameKey,"My device my C#",kAudioAggregateDeviceUIDKey,multIoUtUID,kAudioAggregateDeviceSubDeviceListKey,devices,kAudioAggregateDeviceMasterSubDeviceKey,masterDeviceUID,kAudioAggregateDeviceIsstackedKey,1);
uint aggregateDevice = 0;
var param = (IntPtr)GCHandle.Alloc(dictionary);
uint result = AudioHardwareCreateAggregateDevice(ref param,out aggregateDevice);
return aggregateDevice;
}
有没有人设法使它在Xamarin.Mac中工作?或对绑定问题我有什么建议?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)