Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4054020
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:31:16+00:00 2026-05-20T14:31:16+00:00

I know this question has been somewhat dealt with before, but I feel like

  • 0

I know this question has been somewhat dealt with before, but I feel like we could nail this down a bit better.

Here is my present code. The iPhone automatically plays out the speakers (not the earpiece), but when I plug the earphones in nothing happens. I would like it so that it playback is through the speakers, but will route through the headphones if they are plugged in. How can we change this code to properly do this?

    // ORIGINAL CODE
     UInt32 category = kAudioSessionCategory_PlayAndRecord; 
     error = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(category), &category);
    if (error) printf("couldn't set audio category!");

 // I put this chunk in of code myself. To change the audio to go the speakers (not the earpiece).
 // I don't think this is the best way to do this.      


    UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
    AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T14:31:16+00:00Added an answer on May 20, 2026 at 2:31 pm

    I did it this way:

     OSStatus error = AudioSessionInitialize(NULL, NULL, NULL, NULL);
    
    if (error) printf("ERROR INITIALIZING AUDIO SESSION! %d\n", error);
    else 
    {
    UInt32 category = kAudioSessionCategory_PlayAndRecord;  
    // UInt32 category = kAudioSessionCategory_MediaPlayback;   
    
    error = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(category), &category);
    if (error) printf("couldn't set audio category!");
    
    
    // It is bugs when I unplug the headphones! 
    UInt32 doChangeDefaultRoute = 1;        
    AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof (doChangeDefaultRoute), &doChangeDefaultRoute);
    
    
    
    
    error = AudioSessionAddPropertyListener(kAudioSessionProperty_AudioRouteChange, propListener, self);
    if (error) printf("ERROR ADDING AUDIO SESSION PROP LISTENER! %d\n", error);
    UInt32 inputAvailable = 0;
    UInt32 size = sizeof(inputAvailable);
    
    // we do not want to allow recording if input is not available
    error = AudioSessionGetProperty(kAudioSessionProperty_AudioInputAvailable, &size, &inputAvailable);
    if (error) printf("ERROR GETTING INPUT AVAILABILITY! %d\n", error);
    btn_record.enabled = (inputAvailable) ? YES : NO;
    
    // we also need to listen to see if input availability changes
    error = AudioSessionAddPropertyListener(kAudioSessionProperty_AudioInputAvailable, propListener, self);
    if (error) printf("ERROR ADDING AUDIO SESSION PROP LISTENER! %d\n", error);
    
    error = AudioSessionSetActive(true); 
    if (error) printf("AudioSessionSetActive (true) failed");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question has been around, but I found answers a bit foggy,
I know this question has been asked in several variations before, but my question
I know this question has been asked for many times. I've searched but didn't
I know this question has been asked lots of times, but I am not
I know this question has been asked, how to make a site like facebook/gmail
I'm sorry if this question has been asked before, but I'm not even sure
I understand this is a basic question... but I have been stuck on it
I've been diving into scala, and am absolutely loving it so far. I'm getting
I need to present a form that is not backed by an AR model.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.