From d7fe33c34c94e6a248c26bcb3c9fa121b03e6a77 Mon Sep 17 00:00:00 2001 From: kintan Date: Sun, 15 Oct 2023 21:26:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Demo/SwiftUI/Shared/MovieModel.swift | 1 + Sources/KSPlayer/AVPlayer/KSOptions.swift | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Demo/SwiftUI/Shared/MovieModel.swift b/Demo/SwiftUI/Shared/MovieModel.swift index ea90c79df..c4374f6e7 100644 --- a/Demo/SwiftUI/Shared/MovieModel.swift +++ b/Demo/SwiftUI/Shared/MovieModel.swift @@ -6,6 +6,7 @@ // import CoreData +import CoreMedia import Foundation import KSPlayer #if canImport(UIKit) diff --git a/Sources/KSPlayer/AVPlayer/KSOptions.swift b/Sources/KSPlayer/AVPlayer/KSOptions.swift index 21dfdc5da..da11b0499 100644 --- a/Sources/KSPlayer/AVPlayer/KSOptions.swift +++ b/Sources/KSPlayer/AVPlayer/KSOptions.swift @@ -447,15 +447,16 @@ public extension KSOptions { return Int(ncpu) } - internal static func setAudioSession() { + static func setAudioSession() { #if os(macOS) // try? AVAudioSession.sharedInstance().setRouteSharingPolicy(.longFormAudio) #else let category = AVAudioSession.sharedInstance().category - if category != .playback, category != .playAndRecord { - try? AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, policy: .longFormAudio) + if category == .playback || category == .playAndRecord { + try? AVAudioSession.sharedInstance().setCategory(category, mode: .moviePlayback, policy: .longFormAudio) + } else { + try? AVAudioSession.sharedInstance().setCategory(.playback, mode: .moviePlayback, policy: .longFormAudio) } - try? AVAudioSession.sharedInstance().setMode(.moviePlayback) try? AVAudioSession.sharedInstance().setActive(true) #endif }