且构网

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

在播放一些背景音乐的同​​时播放和录制视频

更新时间:2023-10-29 20:02:28

当您使用* 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.