mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-22 08:10:59 +00:00
28 lines
800 B
Swift
28 lines
800 B
Swift
|
// Copyright © 2021 Metabolist. All rights reserved.
|
||
|
|
||
|
import AVKit
|
||
|
|
||
|
extension AVAudioSession {
|
||
|
static func incrementPresentedPlayerViewControllerCount() {
|
||
|
presentedPlayerViewControllerCount += 1
|
||
|
}
|
||
|
|
||
|
static func decrementPresentedPlayerViewControllerCount() {
|
||
|
presentedPlayerViewControllerCount -= 1
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private extension AVAudioSession {
|
||
|
static var presentedPlayerViewControllerCount = 0 {
|
||
|
didSet {
|
||
|
let instance = sharedInstance()
|
||
|
|
||
|
if presentedPlayerViewControllerCount > 0, instance.category != .playback {
|
||
|
try? instance.setCategory(.playback, mode: .default)
|
||
|
} else if instance.category != .ambient {
|
||
|
try? instance.setCategory(.ambient, mode: .default)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|