繁体   English   中英

检测是否拔出耳机-Monotouch

[英]Detect Headphones Unplugged - Monotouch

有没有办法检测Monotouch是否已拔掉耳机? 我正在尝试寻找AudioSessionAddPropertyListener方法,但没有看到它。 这种方法移植了什么?

这是Apple的文档: 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);

有没有办法检测Monotouch是否已拔掉耳机?

我不确定,但是...

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM