在直播準備推流的時候或者播放器準備播放的時候,設置下面的參數:
當其它消息打斷之后會繼續播放的設置
/* 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 {
}