2

I´m trying to use Novocaine to play some audio withe high performance, but the sample code I found plays the audio only in the earphone, but I want it to play it on the speaker... is that possible?

thanks

Badjano
  • 418
  • 7
  • 23
  • I've never heard of [Novocaine](http://alexbw.github.com/novocaine/) before, nice find. Where did you get the sample code from? – Michael Dautermann Dec 09 '12 at 06:23
  • 1
    Hint: plug off your headphones. –  Dec 09 '12 at 06:41
  • @MichaelDautermann this is simply awesome. –  Dec 09 '12 at 06:42
  • I´m sorry, I didn´t mean the headphones, I meant the hole which you put your ear to talk to people you call, and I wanted the sound to play on speaker – Badjano Dec 10 '12 at 00:08
  • this is where I got the sample from: https://github.com/alexbw/novocaine/blob/master/Novocaine%20iOS%20Example/ViewController.mm – Badjano Dec 10 '12 at 00:09

2 Answers2

5

I have implemented the route change like this and it seems to work. Just replace sessionPropertyListener with the code below and add updateAudioRoute.

void sessionPropertyListener(void *                  inClientData,
                             AudioSessionPropertyID  inID,
                             UInt32                  inDataSize,
                             const void *            inData){


    if (inID == kAudioSessionProperty_AudioRouteChange)
    {
        Novocaine *sm = (Novocaine *)inClientData;
        [sm checkSessionProperties];
        [sm updateAudioRoute];
    }
}

//Quick and dirty way to override the audioRoute whenever the audioRoute is changed.
- (void)updateAudioRoute {
  CFStringRef newRoute;
  UInt32 size = sizeof(CFStringRef);
  CheckError(AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &size, &newRoute), 
             "couldn't get new audio route");
  if (newRoute)
  {
    CFShow(newRoute);
    if (CFStringCompare(newRoute, CFSTR("ReceiverAndMicrophone"), (UInt32)NULL)== kCFCompareEqualTo)
    {
      UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
      AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
    }
    else if (CFStringCompare(newRoute, CFSTR("HeadsetInOut"), (UInt32)NULL) == kCFCompareEqualTo)
    {
      UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_None;
      AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
    }
  }
}
omygaudio
  • 631
  • 5
  • 6
3

had almost the same problem. quick and dirty fix, add this:

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

to the end of iOS section in - (void)setupAudio in your Novocaine.m
Be aware, that this will play the audio via speakers even if headphones are plugged in!

seems to me, that the route change is not implemented yet, as -(void)selectAudioDevice is empty.

Maximilian Körner
  • 846
  • 11
  • 31