mirror of
https://github.com/cranci1/Sora.git
synced 2026-03-11 17:45:37 +00:00
fixed battery indicator not hiding
This commit is contained in:
parent
9b610a3b16
commit
c0e94cbe5a
1 changed files with 4 additions and 20 deletions
|
|
@ -183,7 +183,8 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
watchNextButton,
|
watchNextButton,
|
||||||
volumeSliderHostingView,
|
volumeSliderHostingView,
|
||||||
pipButton,
|
pipButton,
|
||||||
airplayButton
|
airplayButton,
|
||||||
|
timeBatteryContainer
|
||||||
].compactMap { $0 }
|
].compactMap { $0 }
|
||||||
|
|
||||||
private var originalHiddenStates: [UIView: Bool] = [:]
|
private var originalHiddenStates: [UIView: Bool] = [:]
|
||||||
|
|
@ -237,13 +238,9 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
}
|
}
|
||||||
|
|
||||||
let asset: AVURLAsset
|
let asset: AVURLAsset
|
||||||
|
|
||||||
// Check if this is a local file URL
|
|
||||||
if url.scheme == "file" {
|
if url.scheme == "file" {
|
||||||
// For local files, don't add HTTP headers
|
|
||||||
Logger.shared.log("Loading local file: \(url.absoluteString)", type: "Debug")
|
Logger.shared.log("Loading local file: \(url.absoluteString)", type: "Debug")
|
||||||
|
|
||||||
// Check if file exists
|
|
||||||
if FileManager.default.fileExists(atPath: url.path) {
|
if FileManager.default.fileExists(atPath: url.path) {
|
||||||
Logger.shared.log("Local file exists at path: \(url.path)", type: "Debug")
|
Logger.shared.log("Local file exists at path: \(url.path)", type: "Debug")
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -252,7 +249,6 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
|
|
||||||
asset = AVURLAsset(url: url)
|
asset = AVURLAsset(url: url)
|
||||||
} else {
|
} else {
|
||||||
// For remote URLs, add HTTP headers
|
|
||||||
Logger.shared.log("Loading remote URL: \(url.absoluteString)", type: "Debug")
|
Logger.shared.log("Loading remote URL: \(url.absoluteString)", type: "Debug")
|
||||||
var request = URLRequest(url: url)
|
var request = URLRequest(url: url)
|
||||||
if let mydict = headers, !mydict.isEmpty {
|
if let mydict = headers, !mydict.isEmpty {
|
||||||
|
|
@ -271,8 +267,6 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
|
|
||||||
let playerItem = AVPlayerItem(asset: asset)
|
let playerItem = AVPlayerItem(asset: asset)
|
||||||
self.player = AVPlayer(playerItem: playerItem)
|
self.player = AVPlayer(playerItem: playerItem)
|
||||||
|
|
||||||
// Add error observation
|
|
||||||
playerItem.addObserver(self, forKeyPath: "status", options: [.new], context: &playerItemKVOContext)
|
playerItem.addObserver(self, forKeyPath: "status", options: [.new], context: &playerItemKVOContext)
|
||||||
|
|
||||||
Logger.shared.log("Created AVPlayerItem with status: \(playerItem.status.rawValue)", type: "Debug")
|
Logger.shared.log("Created AVPlayerItem with status: \(playerItem.status.rawValue)", type: "Debug")
|
||||||
|
|
@ -1396,7 +1390,7 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
pipButton.widthAnchor.constraint(equalToConstant: 44),
|
pipButton.widthAnchor.constraint(equalToConstant: 44),
|
||||||
pipButton.heightAnchor.constraint(equalToConstant: 44),
|
pipButton.heightAnchor.constraint(equalToConstant: 44),
|
||||||
airplayButton.centerYAnchor.constraint(equalTo: pipButton.centerYAnchor),
|
airplayButton.centerYAnchor.constraint(equalTo: pipButton.centerYAnchor),
|
||||||
airplayButton.trailingAnchor.constraint(equalTo: pipButton.leadingAnchor, constant: -6),
|
airplayButton.trailingAnchor.constraint(equalTo: pipButton.leadingAnchor, constant: -4),
|
||||||
airplayButton.widthAnchor.constraint(equalToConstant: 44),
|
airplayButton.widthAnchor.constraint(equalToConstant: 44),
|
||||||
airplayButton.heightAnchor.constraint(equalToConstant: 44)
|
airplayButton.heightAnchor.constraint(equalToConstant: 44)
|
||||||
])
|
])
|
||||||
|
|
@ -2836,7 +2830,6 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
}
|
}
|
||||||
|
|
||||||
private func setupTimeBatteryIndicator() {
|
private func setupTimeBatteryIndicator() {
|
||||||
// Create container
|
|
||||||
let container = UIView()
|
let container = UIView()
|
||||||
container.translatesAutoresizingMaskIntoConstraints = false
|
container.translatesAutoresizingMaskIntoConstraints = false
|
||||||
container.backgroundColor = .clear
|
container.backgroundColor = .clear
|
||||||
|
|
@ -2844,7 +2837,6 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
controlsContainerView.addSubview(container)
|
controlsContainerView.addSubview(container)
|
||||||
self.timeBatteryContainer = container
|
self.timeBatteryContainer = container
|
||||||
|
|
||||||
// Create time label
|
|
||||||
let timeLabel = UILabel()
|
let timeLabel = UILabel()
|
||||||
timeLabel.translatesAutoresizingMaskIntoConstraints = false
|
timeLabel.translatesAutoresizingMaskIntoConstraints = false
|
||||||
timeLabel.textColor = .white
|
timeLabel.textColor = .white
|
||||||
|
|
@ -2853,13 +2845,11 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
container.addSubview(timeLabel)
|
container.addSubview(timeLabel)
|
||||||
self.timeLabel = timeLabel
|
self.timeLabel = timeLabel
|
||||||
|
|
||||||
// Create separator
|
|
||||||
let separator = UIView()
|
let separator = UIView()
|
||||||
separator.translatesAutoresizingMaskIntoConstraints = false
|
separator.translatesAutoresizingMaskIntoConstraints = false
|
||||||
separator.backgroundColor = .white.withAlphaComponent(0.5)
|
separator.backgroundColor = .white.withAlphaComponent(0.5)
|
||||||
container.addSubview(separator)
|
container.addSubview(separator)
|
||||||
|
|
||||||
// Create battery label
|
|
||||||
let batteryLabel = UILabel()
|
let batteryLabel = UILabel()
|
||||||
batteryLabel.translatesAutoresizingMaskIntoConstraints = false
|
batteryLabel.translatesAutoresizingMaskIntoConstraints = false
|
||||||
batteryLabel.textColor = .white
|
batteryLabel.textColor = .white
|
||||||
|
|
@ -2868,7 +2858,6 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
container.addSubview(batteryLabel)
|
container.addSubview(batteryLabel)
|
||||||
self.batteryLabel = batteryLabel
|
self.batteryLabel = batteryLabel
|
||||||
|
|
||||||
// Setup constraints
|
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
container.centerXAnchor.constraint(equalTo: controlsContainerView.centerXAnchor),
|
container.centerXAnchor.constraint(equalTo: controlsContainerView.centerXAnchor),
|
||||||
container.topAnchor.constraint(equalTo: sliderHostingController?.view.bottomAnchor ?? controlsContainerView.bottomAnchor, constant: 2),
|
container.topAnchor.constraint(equalTo: sliderHostingController?.view.bottomAnchor ?? controlsContainerView.bottomAnchor, constant: 2),
|
||||||
|
|
@ -2889,19 +2878,14 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
batteryLabel.widthAnchor.constraint(equalToConstant: 50)
|
batteryLabel.widthAnchor.constraint(equalToConstant: 50)
|
||||||
])
|
])
|
||||||
|
|
||||||
// Start time updates
|
|
||||||
updateTime()
|
updateTime()
|
||||||
timeUpdateTimer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { [weak self] _ in
|
timeUpdateTimer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { [weak self] _ in
|
||||||
self?.updateTime()
|
self?.updateTime()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup battery monitoring
|
|
||||||
UIDevice.current.isBatteryMonitoringEnabled = true
|
UIDevice.current.isBatteryMonitoringEnabled = true
|
||||||
updateBatteryLevel()
|
updateBatteryLevel()
|
||||||
NotificationCenter.default.addObserver(self,
|
NotificationCenter.default.addObserver(self, selector: #selector(batteryLevelDidChange), name: UIDevice.batteryLevelDidChangeNotification, object: nil)
|
||||||
selector: #selector(batteryLevelDidChange),
|
|
||||||
name: UIDevice.batteryLevelDidChangeNotification,
|
|
||||||
object: nil)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func updateTime() {
|
private func updateTime() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue