title: iOS - Sending one audio stream to the built-in speaker and a different stream to a Bluetooth HFP speaker
body: <p>I am building an alarm clock app which works in conjunction with a physical Bluetooth device. I need to send one audio file (a song selected from the iTunes Library) to the built-in speaker and a separate audio file to the Bluetooth device (which is, effectively, a Bluetooth HFP speaker) at the same time.</p>
  
  <p>My first thought in completing this would be to use <code>AVAudioSession</code>'s new <code>AVAudioSessionCategoryMultiRoute</code>, but iOS 7 does not detect my speaker as a possible route; it will detect <em>either</em> the built-in speaker <em>or</em> the HFP speaker, but it will not detect both simultaneously. Detecting both is required to send two files at the same time.</p>
  
  <p>My second thought was to use <code>AVAudioSessionCategoryPlayAndRecord</code> (even though the app has no need for a microphone) and to use <code>overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker</code> and <code>overrideOutputAudioPort:AVAudioSessionPortOverrideNone</code> like so:</p>
  
  <pre><code>NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"alarm"
                                                            ofType:@"m4a"];
  
  NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
  
  self.bluetoothAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL
                                                                 error:nil];
  
  self.bluetoothAudioPlayer.delegate = self;
  
  [self.bluetoothAudioPlayer play];
  
  NSError *error = nil;
  
  NSURL *selectedSongURL = [self.selectedSong valueForProperty:MPMediaItemPropertyAssetURL];
  
  NSLog(@"selectedSongURL: %@", selectedSongURL);
  
  if (selectedSongURL) {
      if (![[AVAudioSession sharedInstance] overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:&amp;error]) {
          NSLog(@"overrideOutput error: %@", error);
      }
      self.internalAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:selectedSongURL error:nil];
      self.internalAudioPlayer.delegate = self;
      [self.internalAudioPlayer play];
  }
  </code></pre>
  
  <p>After this alarm is silenced, I run <code>[[AVAudioSession sharedInstance] overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:nil];</code> to reset the override call.</p>
  
  <p>However, this doesn't work because iOS just puts both audio signals on the same speaker.</p>
  
  <p>Is there a way to send one audio stream to a Bluetooth HFP speaker and a different audio stream to the built-in speaker?</p>