iphone - Is it possible to Redirect audio output to phone speaker or headset in iOS programmatically -
i developing application in want redirect audio output phone speaker, don't have idea how programmatically.
any idea it?
you cannot turn on/off speakers through app. however, can sense mute switch of device. can know current status of speaker. this question lead towards solution.
for sake of completeness, let me paste answer here..
// "ambient" makes respect mute switch // must call once init session if (!gaudiosessioninited) { audiosessioninterruptionlistener ininterruptionlistener = null; osstatus error; if ((error = audiosessioninitialize (null, null, ininterruptionlistener, null))) { nslog(@"*** error *** error in audiosessioninitialize: %d.", error); } else { gaudiosessioninited = yes; } } sint32 ambient = kaudiosessioncategory_ambientsound; if (audiosessionsetproperty (kaudiosessionproperty_audiocategory, sizeof (ambient), &ambient)) { nslog(@"*** error *** not set session property ambient."); }
update: need override audioroute turn on speakers when headset plugged in. use following code same.
uint32 audiorouteoverride = kaudiosessionoverrideaudioroute_speaker; audiosessionsetproperty (kaudiosessionproperty_overrideaudioroute,sizeof (audiorouteoverride),&audiorouteoverride);
be sure include audiotoolbox lib in xcode. think solve issue..
let me know if more info needed..:)
Comments
Post a Comment