且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在播放一些backgorund音乐时播放和录制视频

更新时间:2023-10-29 18:23:10

当您使用* kAudioSessionProperty_OverrideCategoryMixWithOthers *覆盖seesion类别时,它使用顶部较小的扬声器设备(除了前端摄像头)。要将常规扬声器用作输出设备,您应该改为重定向音频会话的输出路径。以下是实现此目的的代码片段

When you override the seesion category with *kAudioSessionProperty_OverrideCategoryMixWithOthers* it uses the smaller speaker on the top side of the device (besides the frontend camera). To use the regular speaker as the output device, you should instead redirect the output route of your audio session. The following is the code snippet of achieving this

UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;

AudioSessionSetProperty ( 
    kAudioSessionProperty_OverrideAudioRoute,                         
    sizeof (audioRouteOverride),                                      
    &audioRouteOverride                                               
); 

将此代码替换为您的代码,它将起作用。您可以进一步参考重定向输出音频

Replace this code with your above and it will work. You can further refer Redirect Output Audio on apple developer portal.