Skip to content

Commit

Permalink
fix #609
Browse files Browse the repository at this point in the history
  • Loading branch information
kingslay committed Nov 6, 2023
1 parent 6c24a94 commit 21c6d61
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Sources/KSPlayer/AVPlayer/KSOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -507,22 +507,25 @@ public extension KSOptions {
KSLog("[audio] isSpatialAudioEnabled: \(isSpatialAudioEnabled)")
let isUseAudioRenderer = KSOptions.audioPlayerType == AudioRendererPlayer.self
KSLog("[audio] isUseAudioRenderer: \(isUseAudioRenderer)")
let maxRouteChannelsCount = AVAudioSession.sharedInstance().currentRoute.outputs.compactMap {
$0.channels?.count
}.max() ?? 2
KSLog("[audio] currentRoute max channels: \(maxRouteChannelsCount)")
var channelCount = channelCount
if channelCount > 2 {
let minChannels = min(maximumOutputNumberOfChannels, channelCount)
if minChannels > preferredOutputNumberOfChannels {
try? AVAudioSession.sharedInstance().setPreferredOutputNumberOfChannels(Int(minChannels))
KSLog("[audio] set preferredOutputNumberOfChannels: \(minChannels)")
}
// iOS 有空间音频功能,所以不用处理
#if os(tvOS) || targetEnvironment(simulator)
if !(isUseAudioRenderer && isSpatialAudioEnabled) {
let maxRouteChannelsCount = AVAudioSession.sharedInstance().currentRoute.outputs.compactMap {
$0.channels?.count
}.max() ?? 2
KSLog("[audio] currentRoute max channels: \(maxRouteChannelsCount)")
// 不要用maxRouteChannelsCount来panduan,有可能会不准。导致多音道设备也返回2(一开始播放一个2声道,就容易出现)
// channelCount = AVAudioChannelCount(min(AVAudioSession.sharedInstance().outputNumberOfChannels, maxRouteChannelsCount))
channelCount = AVAudioChannelCount(AVAudioSession.sharedInstance().outputNumberOfChannels)
}
#endif
} else {
channelCount = 2
}
Expand Down

0 comments on commit 21c6d61

Please sign in to comment.