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?
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?
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
);
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.
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);
}