Question

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

Was it helpful?

Solution 2

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.

OTHER TIPS

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);
    }
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top