iOS - 将一个音频流发送到内置扬声器,将另一个音频流发送到蓝牙HFP扬声器

Tim*_* B. 5 iphone audio bluetooth ios

我正在构建一个与物理蓝牙设备配合使用的闹钟应用程序.我需要将一个音频文件(从iTunes资料库中选择的一首歌)发送到内置扬声器,并将一个单独的音频文件同时发送到蓝牙设备(实际上是蓝牙HFP扬声器).

我完成这个的第一个想法是使用AVAudioSession新的AVAudioSessionCategoryMultiRoute,但iOS 7没有检测到我的扬声器作为可能的路线; 它会检测无论是内置扬声器 HFP的扬声器,但是它不会同时检测两种.检测两者需要同时发送两个文件.

我的第二个想法是使用AVAudioSessionCategoryPlayAndRecord(即使应用程序不需要麦克风)并使用overrideOutputAudioPort:AVAudioSessionPortOverrideSpeakeroverrideOutputAudioPort:AVAudioSessionPortOverrideNone喜欢这样:

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:&error]) {
        NSLog(@"overrideOutput error: %@", error);
    }
    self.internalAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:selectedSongURL error:nil];
    self.internalAudioPlayer.delegate = self;
    [self.internalAudioPlayer play];
}
Run Code Online (Sandbox Code Playgroud)

在此警报静音后,我运行[[AVAudioSession sharedInstance] overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:nil];以重置覆盖调用.

但是,这不起作用,因为iOS只是将两个音频信号放在同一个扬声器上.

有没有办法将一个音频流发送到蓝牙HFP扬声器,将另一个音频流发送到内置扬声器?