mirror of
https://github.com/cranci1/Sora.git
synced 2026-04-21 00:22:12 +00:00
ok yes im dumb. Also maybe fixed #153
This commit is contained in:
parent
491716b1e2
commit
a6ba2db81f
2 changed files with 26 additions and 12 deletions
|
|
@ -154,6 +154,7 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
private var playerItemKVOContext = 0
|
private var playerItemKVOContext = 0
|
||||||
private var loadedTimeRangesObservation: NSKeyValueObservation?
|
private var loadedTimeRangesObservation: NSKeyValueObservation?
|
||||||
private var playerTimeControlStatusObserver: NSKeyValueObservation?
|
private var playerTimeControlStatusObserver: NSKeyValueObservation?
|
||||||
|
private var playerRateObserver: NSKeyValueObservation?
|
||||||
|
|
||||||
private var controlsLocked = false
|
private var controlsLocked = false
|
||||||
private var lockButtonTimer: Timer?
|
private var lockButtonTimer: Timer?
|
||||||
|
|
@ -255,14 +256,6 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
view.backgroundColor = .black
|
view.backgroundColor = .black
|
||||||
|
|
||||||
backgroundToken = NotificationCenter.default.addObserver(forName: UIApplication.willResignActiveNotification, object: nil, queue: .main ) { [weak self] _ in
|
|
||||||
self?.handleEnterBackground()
|
|
||||||
}
|
|
||||||
|
|
||||||
foregroundToken = NotificationCenter.default.addObserver(forName: UIApplication.didBecomeActiveNotification, object: nil, queue: .main ) { [weak self] _ in
|
|
||||||
self?.handleBecomeActive()
|
|
||||||
}
|
|
||||||
|
|
||||||
setupHoldGesture()
|
setupHoldGesture()
|
||||||
loadSubtitleSettings()
|
loadSubtitleSettings()
|
||||||
setupPlayerViewController()
|
setupPlayerViewController()
|
||||||
|
|
@ -317,6 +310,17 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
Logger.shared.log("Error activating audio session: \(error)", type: "Debug")
|
Logger.shared.log("Error activating audio session: \(error)", type: "Debug")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
playerRateObserver = player.observe(\.rate, options: [.new, .old]) { [weak self] player, change in
|
||||||
|
guard let self = self else { return }
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
let isActuallyPlaying = player.rate != 0
|
||||||
|
if self.isPlaying != isActuallyPlaying {
|
||||||
|
self.isPlaying = isActuallyPlaying
|
||||||
|
self.playPauseButton.image = UIImage(systemName: isActuallyPlaying ? "pause.fill" : "play.fill")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
volumeViewModel.value = Double(audioSession.outputVolume)
|
volumeViewModel.value = Double(audioSession.outputVolume)
|
||||||
|
|
||||||
volumeObserver = audioSession.observe(\.outputVolume, options: [.new]) { [weak self] session, change in
|
volumeObserver = audioSession.observe(\.outputVolume, options: [.new]) { [weak self] session, change in
|
||||||
|
|
@ -418,11 +422,21 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
if let token = timeObserverToken {
|
playerRateObserver?.invalidate()
|
||||||
player.removeTimeObserver(token)
|
inactivityTimer?.invalidate()
|
||||||
}
|
updateTimer?.invalidate()
|
||||||
|
lockButtonTimer?.invalidate()
|
||||||
|
dimButtonTimer?.invalidate()
|
||||||
|
loadedTimeRangesObservation?.invalidate()
|
||||||
|
playerTimeControlStatusObserver?.invalidate()
|
||||||
|
volumeObserver?.invalidate()
|
||||||
|
|
||||||
|
player.replaceCurrentItem(with: nil)
|
||||||
player.pause()
|
player.pause()
|
||||||
|
|
||||||
|
playerViewController = nil
|
||||||
|
sliderHostingController = nil
|
||||||
|
try? AVAudioSession.sharedInstance().setActive(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
|
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
|
||||||
|
|
|
||||||
|
|
@ -421,7 +421,7 @@ struct SettingsViewData: View {
|
||||||
let formatter = ByteCountFormatter()
|
let formatter = ByteCountFormatter()
|
||||||
formatter.allowedUnits = [.useBytes, .useKB, .useMB, .useGB]
|
formatter.allowedUnits = [.useBytes, .useKB, .useMB, .useGB]
|
||||||
formatter.countStyle = .file
|
formatter.countStyle = .file
|
||||||
return formatter.string(fromByteCount: bytes) ?? "\(bytes) bytes"
|
return formatter.string(fromByteCount: bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateSizes() {
|
func updateSizes() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue