直播app推流的时候设置其它音乐播放器播放背景音乐

在直播准备推流的时候或者播放器准备播放的时候,设置下面的参数:

当其它消息打断之后会继续播放的设置

/*  options for use when calling setActive:withOptions:error: 
AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation -- 
Notify an interrupted app that the interruption has ended and it may resume playback. Only valid on 
session deactivation. */
do {         
   try AVAudioSession.sharedInstance().setActive(false, with: AVAudioSessionSetActiveOptions.notifyOthersOnDeactivation)
} catch {
}

设置让app的声音和其他音乐兼容(默认是不兼容的),例如在直播的时候,用手机其它音乐软件同时播放音乐。

do {
    try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, with: AVAudioSessionCategoryOptions.mixWithOthers)
} catch {
}

你可能感兴趣的:(直播app推流的时候设置其它音乐播放器播放背景音乐)