1

Is there a way to detect if headphones are unplugged in Monotouch? I am trying to look for the AudioSessionAddPropertyListener method but don't see it. What this method ported over?

Here is Apple's docs: http://developer.apple.com/library/ios/#documentation/AudioToolbox/Reference/AudioSessionServicesReference/Reference/reference.html#//apple_ref/doc/constant_group/Audio_Session_Interruption_States

If anyone wants to see the code for how to do this, you can do the following:

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);
user472292
  • 1,069
  • 2
  • 22
  • 37

1 Answers1

1

Is there a way to detect if headphones are unplugged in Monotouch?

I'm not sure but...

I am trying to look for the AudioSessionAddPropertyListener method but don't see it. What this method ported over?

The native call to AudioSessionAddPropertyListener maps to MonoTouch's AudioSession.AddListener static method.

poupou
  • 43,413
  • 6
  • 77
  • 174
  • Excellent. That is what I needed. Is there a spot you looked to see how the API is mapped (between MonoTouch and the native call)? – user472292 Dec 12 '11 at 19:23
  • Miguel's rosetta stone http://tirania.org/tmp/rosetta.html is the best resource when dealing with (Objective-C) selectors but it does not currently shows the pinvokes to C libraries. In general the bindings keeps the naming similar enough that MonoDevelop IDE autocompletion should suggest you likely candidates. – poupou Dec 12 '11 at 19:42