iPhone audio playback: force through internal speaker?

后端 未结 2 721
抹茶落季
抹茶落季 2020-12-01 08:52

Does anyone know if it is possible to implement playback of an audio file through the internal speaker even if the headphones are plugged in?

相关标签:
2条回答
  • 2020-12-01 09:31

    I'm not sure how you are doing your audio playback, but try having a look at the "Redirecting Output Audio" section of the Audio Session Programming Guide

    It looks something like this:

    UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;  // 1 
    AudioSessionSetProperty ( 
        kAudioSessionProperty_OverrideAudioRoute,                         // 2 
        sizeof (audioRouteOverride),                                      // 3 
        &audioRouteOverride                                               // 4 
    ); 
    
    0 讨论(0)
  • 2020-12-01 09:32

    Actually i think this is not possible, as there seems to be some kind of mechanical switch, which indicates a plugged in headset thus preventing speaker output when this is the case. (read here)

    Some other hints can be found in the description of kAudioSessionProperty_OverrideCategoryDefaultToSpeaker: "Specifies whether or not to route audio to the speaker (instead of to the receiver) when no other audio route, such as a headset, is connected."

    0 讨论(0)
提交回复
热议问题