我想将我的应用程序的音频播放到Xamarin中的蓝牙扬声器。
我试过这段代码。它不起作用。它会引发错误,例如MBluetoothAdapter.GetProfileProxy
的无效转换异常。任何人都可以建议如何在 Xamarin.Android ?
private IBluetoothProfileServiceListener _bluetoothProfileServiceListener;
public BluetoothAdapter MBluetoothAdapter;
在onCreate
:
MBluetoothAdapter = BluetoothAdapter.DefaultAdapter;
_bluetoothProfileServiceListener = new ServiceListener();
MBluetoothAdapter.GetProfileProxy(BaseContext,
_bluetoothProfileServiceListener, ProfileType.A2dp);
private class ServiceListener : IBluetoothProfileServiceListener
{
public void Dispose()
{
}
public IntPtr Handle { get; }
public void OnServiceConnected(ProfileType profile,IBluetoothProfile proxy)
{
if (profile == ProfileType.A2dp)
{
//service connected
}
}
public void OnServiceDisconnected(ProfileType profile)
{
}
}