0

I have a small app. In this app, the loud speaker makes noise every a certain time that I set up.

Now, I want it makes noise over it's built-in speaker even if a headset jack is plugged in the device.

How can I do this?

Tim Visée
  • 2,988
  • 4
  • 45
  • 55
theson
  • 3
  • 2

3 Answers3

0

you can try the below code to play code on speaker.

Also check the this

Hope this will help you.

[[AVAudioSession sharedInstance] setDelegate:self];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];


UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;

AudioSessionSetProperty (
                         kAudioSessionProperty_OverrideAudioRoute,
                         sizeof (audioRouteOverride),
                         &audioRouteOverride
                         );
Shubhendu
  • 1,081
  • 8
  • 13
  • I used your above code but when I plugged a headset jack, the sound did not loud anymore :( – theson Jul 21 '14 at 02:20
  • the above code works well on my device while earphone is plugged in. you can try this link- http://uihacker.blogspot.in/2013/08/ios-force-audio-output-to-speakers.html – Shubhendu Jul 21 '14 at 03:14
  • This code works for me when a headset jack was already plugged in. If the speaker is making noise then I plug a headset into my device, it became silent. – theson Jul 21 '14 at 04:02
  • You can check this link- http://stackoverflow.com/questions/6922898/cant-get-a-notification-when-connecting-an-external-accessory-to-the-3-5-mm-hea – Shubhendu Jul 21 '14 at 05:12
  • Thank Shubhendu, I will check it again :) – theson Jul 21 '14 at 08:15
0

You have to Override the Audio Route AFTER the headphones are plugged in. Your app can request an Audio Session Notification for when this occurs, and then do the Override again.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
0

This work for me.

+ (void)sessionAudioPort {
    UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
    AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
    UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
    AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
}
jose920405
  • 7,982
  • 6
  • 45
  • 71