1
0
mirror of https://github.com/metabolist/metatext synced 2024-12-27 02:02:38 +01:00
metatext-app-ios-iphone-ipad/Extensions/AVAudioSession+Extensions.swift
2021-03-05 13:50:01 -08:00

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)
}
}
}
}