iphone - 连接到汽车的蓝牙后,系统声音服务将无法播放音频

标签 iphone ios audio sdk system

我正在使用系统声音服务在应用程序中播放音频
当使用扬声器,耳机或什至坞站USB汽车立体声连接时,它可以完美工作。
但是,当电话连接到车载蓝牙系统时,音频不会播放。

我可以想象,由于它已连接到蓝牙设备,因此系统声音服务将尝试通过蓝牙发送音频。

有谁知道我如何防止音频路由尝试通过蓝牙发送到声音?

这是我正在使用的代码:

CFURLRef        soundFileURLRef;
SystemSoundID   soundFileObject;

CFBundleRef mainBundle;
mainBundle = CFBundleGetMainBundle ();

// Get the URL to the sound file to play
soundFileURLRef  =  CFBundleCopyResourceURL (
                                                 mainBundle,
                                                 CFSTR ("Alert6"),
                                                 CFSTR ("aif"),
                                                 NULL
                                                 );

// Create a system sound object representing the sound file
    AudioServicesCreateSystemSoundID (
                                      soundFileURLRef,
                                      &soundFileObject
                                      );

AudioServicesPlaySystemSound (soundFileObject);

有任何想法吗?

最佳答案

您可以将输出覆盖到内部扬声器

UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker; // lets the system sounds come out of the speaker
OSStatus err = AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOverride), &audioRouteOverride);
if (err != noErr) {
    // handle error
}

关于iphone - 连接到汽车的蓝牙后,系统声音服务将无法播放音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8028253/

相关文章:

iphone - @selector 中的参数

iphone - CGLayer 和抗锯齿 CGPath

ios - 此 bundle 无效 info.plist 中所需的 key 设备

ios - iOS 中没有分钟和秒的 UIDateTime Picker

iphone - 为什么此代码中需要 "sizeToFit"调用?

iphone - writeToFile 如何判断何时完成

java: 样本越界异常

Javascript:带按钮的循环声音。 bool 值错误

c - ALSA捕获导致高CPU使用率

ios - 暂时隐藏 UICollectionView Swift iOS 中的单元格