Application sound does not work through speakers

There is a strange error in my application. I use AVAudioPlayer to play sounds (multiple instances), the sound works fine through the headphones, but using the application without the headphones does not cause sound from the speaker. All sound clips are AAC encoded.

I tried to set the AVAudioSession properties both through the Objective-C API ([AVAudioSession sharedInstance]) and the C API, but none of these options work.

+5
source share
3 answers

RESEARCH on iPhone - when the sound was very low - it seemed to come out of the earphone of the phone (not the headphone jack) instead of the bottom speaker - change the DEFAULT TO SPEAKER value

//http://stackoverflow.com/questions/3104562/avaudiorecorder-avaudioplayer-sound-output-on-internal-speaker-how-to-chang


UInt32 doChangeDefaultRoute = 1;
AudioSessionSetProperty (
    kAudioSessionProperty_OverrideCategoryDefaultToSpeaker,
    sizeof (doChangeDefaultRoute),
    &doChangeDefaultRoute
);
+4
source

( ios7) , . ( , )

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord
                                 withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker
                                       error:nil];
+18

For those of you who use Swift Syntax...

Below worked for me.

do {
    try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, withOptions: AVAudioSessionCategoryOptions.DefaultToSpeaker)
   } 
catch {
          print("can't default to speaker ")
      }
+2
source

All Articles