公开本机的“ AudioHardwareCreateAggregateDevice”方法CoreAudio Xamarin.Mac

问题描述

我一直在使用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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...