1

有没有办法检测耳机是否在 Monotouch 中拔出?我正在寻找AudioSessionAddPropertyListener方法,但没有看到。这个方法移植了什么?

这是苹果的文档:http: //developer.apple.com/library/ios/#documentation/AudioToolbox/Reference/AudioSessionServicesReference/Reference/reference.html#//apple_ref/doc/constant_group/Audio_Session_Interruption_States

如果有人想查看如何执行此操作的代码,您可以执行以下操作:

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);
4

1 回答 1

1

有没有办法检测耳机是否在 Monotouch 中拔出?

我不确定,但是...

我正在尝试寻找 AudioSessionAddPropertyListener 方法,但没有看到它。这个方法移植了什么?

本机调用AudioSessionAddPropertyListener映射到 MonoTouch 的AudioSession.AddListener静态方法。

于 2011-12-11T21:27:23.443 回答