有没有办法检测耳机是否在 Monotouch 中拔出?我正在寻找AudioSessionAddPropertyListener方法,但没有看到。这个方法移植了什么?
如果有人想查看如何执行此操作的代码,您可以执行以下操作:
AudioSession.PropertyListener p = delegate(AudioSessionProperty prop, int size, IntPtr data) {
NSDictionary propertyDictionary = new NSDictionary(data);
if (propertyDictionary.ContainsKey(NSObject.FromObject("OutputDeviceDidChange_OldRoute")))
{
string oldRoute = propertyDictionary.ValueForKey(new NSString("OutputDeviceDidChange_OldRoute")).ToString();
if (oldRoute == "Headphone")
{
if (audioPlayer != null)
{
audioPlayer.Pause();
}
}
}
};
AudioSession.AddListener(AudioSessionProperty.AudioRouteChange, p);