mirror of
https://github.com/cranci1/Sora.git
synced 2026-01-11 20:10:24 +00:00
player fixes
This commit is contained in:
parent
c1e3ee3ea3
commit
2cc03e251c
1 changed files with 45 additions and 2 deletions
|
|
@ -43,6 +43,7 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
var updateTimer: Timer?
|
var updateTimer: Timer?
|
||||||
var originalRate: Float = 1.0
|
var originalRate: Float = 1.0
|
||||||
var holdGesture: UILongPressGestureRecognizer?
|
var holdGesture: UILongPressGestureRecognizer?
|
||||||
|
var controlsInactivityTimer: Timer?
|
||||||
|
|
||||||
var isPlaying = true
|
var isPlaying = true
|
||||||
var currentTimeVal: Double = 0.0
|
var currentTimeVal: Double = 0.0
|
||||||
|
|
@ -676,6 +677,9 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
inactivityTimer?.invalidate()
|
inactivityTimer?.invalidate()
|
||||||
inactivityTimer = nil
|
inactivityTimer = nil
|
||||||
|
|
||||||
|
controlsInactivityTimer?.invalidate()
|
||||||
|
controlsInactivityTimer = nil
|
||||||
|
|
||||||
loadedTimeRangesObservation?.invalidate()
|
loadedTimeRangesObservation?.invalidate()
|
||||||
loadedTimeRangesObservation = nil
|
loadedTimeRangesObservation = nil
|
||||||
volumeObserver?.invalidate()
|
volumeObserver?.invalidate()
|
||||||
|
|
@ -910,6 +914,7 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
height: 33,
|
height: 33,
|
||||||
onEditingChanged: { editing in
|
onEditingChanged: { editing in
|
||||||
if editing {
|
if editing {
|
||||||
|
self.resetControlsInactivityTimer()
|
||||||
self.isSliderEditing = true
|
self.isSliderEditing = true
|
||||||
|
|
||||||
self.wasPlayingBeforeSeek = (self.player.timeControlStatus == .playing)
|
self.wasPlayingBeforeSeek = (self.player.timeControlStatus == .playing)
|
||||||
|
|
@ -1027,6 +1032,7 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
|
|
||||||
@objc private func handleTwoFingerTapPause(_ gesture: UITapGestureRecognizer) {
|
@objc private func handleTwoFingerTapPause(_ gesture: UITapGestureRecognizer) {
|
||||||
if gesture.state == .ended {
|
if gesture.state == .ended {
|
||||||
|
resetControlsInactivityTimer()
|
||||||
togglePlayPause()
|
togglePlayPause()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1300,6 +1306,7 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
|
|
||||||
func volumeSlider() {
|
func volumeSlider() {
|
||||||
let container = VolumeSliderContainer(volumeVM: self.volumeViewModel) { newVal in
|
let container = VolumeSliderContainer(volumeVM: self.volumeViewModel) { newVal in
|
||||||
|
self.resetControlsInactivityTimer()
|
||||||
if let sysSlider = self.systemVolumeSlider {
|
if let sysSlider = self.systemVolumeSlider {
|
||||||
sysSlider.value = Float(newVal)
|
sysSlider.value = Float(newVal)
|
||||||
}
|
}
|
||||||
|
|
@ -1731,7 +1738,7 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
}
|
}
|
||||||
|
|
||||||
private func setupQualityButton() {
|
private func setupQualityButton() {
|
||||||
let image = UIImage(systemName: "tv", withConfiguration: bottomControlsCfg)
|
let image = UIImage(systemName: "4k.tv", withConfiguration: bottomControlsCfg)
|
||||||
|
|
||||||
qualityButton = UIButton(type: .system)
|
qualityButton = UIButton(type: .system)
|
||||||
qualityButton.setImage(image, for: .normal)
|
qualityButton.setImage(image, for: .normal)
|
||||||
|
|
@ -2061,17 +2068,41 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
}
|
}
|
||||||
|
|
||||||
if isControlsVisible {
|
if isControlsVisible {
|
||||||
|
startControlsInactivityTimer()
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
||||||
self.setupControlButtonsContainer()
|
self.setupControlButtonsContainer()
|
||||||
self.updateSkipButtonsVisibility()
|
self.updateSkipButtonsVisibility()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
stopControlsInactivityTimer()
|
||||||
updateSkipButtonsVisibility()
|
updateSkipButtonsVisibility()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func startControlsInactivityTimer() {
|
||||||
|
stopControlsInactivityTimer()
|
||||||
|
controlsInactivityTimer = Timer.scheduledTimer(withTimeInterval: 3.0, repeats: false) { [weak self] _ in
|
||||||
|
guard let self = self else { return }
|
||||||
|
if self.isControlsVisible {
|
||||||
|
self.toggleControls()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func stopControlsInactivityTimer() {
|
||||||
|
controlsInactivityTimer?.invalidate()
|
||||||
|
controlsInactivityTimer = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
private func resetControlsInactivityTimer() {
|
||||||
|
if isControlsVisible {
|
||||||
|
startControlsInactivityTimer()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@objc func seekBackwardLongPress(_ gesture: UILongPressGestureRecognizer) {
|
@objc func seekBackwardLongPress(_ gesture: UILongPressGestureRecognizer) {
|
||||||
if gesture.state == .began {
|
if gesture.state == .began {
|
||||||
|
resetControlsInactivityTimer()
|
||||||
let holdValue = UserDefaults.standard.double(forKey: "skipIncrementHold")
|
let holdValue = UserDefaults.standard.double(forKey: "skipIncrementHold")
|
||||||
let finalSkip = holdValue > 0 ? holdValue : 30
|
let finalSkip = holdValue > 0 ? holdValue : 30
|
||||||
currentTimeVal = max(currentTimeVal - finalSkip, 0)
|
currentTimeVal = max(currentTimeVal - finalSkip, 0)
|
||||||
|
|
@ -2084,6 +2115,7 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
|
|
||||||
@objc func seekForwardLongPress(_ gesture: UILongPressGestureRecognizer) {
|
@objc func seekForwardLongPress(_ gesture: UILongPressGestureRecognizer) {
|
||||||
if gesture.state == .began {
|
if gesture.state == .began {
|
||||||
|
resetControlsInactivityTimer()
|
||||||
let holdValue = UserDefaults.standard.double(forKey: "skipIncrementHold")
|
let holdValue = UserDefaults.standard.double(forKey: "skipIncrementHold")
|
||||||
let finalSkip = holdValue > 0 ? holdValue : 30
|
let finalSkip = holdValue > 0 ? holdValue : 30
|
||||||
currentTimeVal = min(currentTimeVal + finalSkip, duration)
|
currentTimeVal = min(currentTimeVal + finalSkip, duration)
|
||||||
|
|
@ -2095,6 +2127,7 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func seekBackward() {
|
@objc func seekBackward() {
|
||||||
|
resetControlsInactivityTimer()
|
||||||
let skipValue = UserDefaults.standard.double(forKey: "skipIncrement")
|
let skipValue = UserDefaults.standard.double(forKey: "skipIncrement")
|
||||||
let finalSkip = skipValue > 0 ? skipValue : 10
|
let finalSkip = skipValue > 0 ? skipValue : 10
|
||||||
|
|
||||||
|
|
@ -2106,6 +2139,7 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func seekForward() {
|
@objc func seekForward() {
|
||||||
|
resetControlsInactivityTimer()
|
||||||
let skipValue = UserDefaults.standard.double(forKey: "skipIncrement")
|
let skipValue = UserDefaults.standard.double(forKey: "skipIncrement")
|
||||||
|
|
||||||
let finalSkip = skipValue > 0 ? skipValue : 10
|
let finalSkip = skipValue > 0 ? skipValue : 10
|
||||||
|
|
@ -2117,6 +2151,7 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func handleDoubleTap(_ gesture: UITapGestureRecognizer) {
|
@objc func handleDoubleTap(_ gesture: UITapGestureRecognizer) {
|
||||||
|
resetControlsInactivityTimer()
|
||||||
let tapLocation = gesture.location(in: view)
|
let tapLocation = gesture.location(in: view)
|
||||||
if tapLocation.x < view.bounds.width / 2 {
|
if tapLocation.x < view.bounds.width / 2 {
|
||||||
seekBackward()
|
seekBackward()
|
||||||
|
|
@ -2134,6 +2169,7 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func togglePlayPause() {
|
@objc func togglePlayPause() {
|
||||||
|
resetControlsInactivityTimer()
|
||||||
if isPlaying {
|
if isPlaying {
|
||||||
currentPlaybackSpeed = player.rate
|
currentPlaybackSpeed = player.rate
|
||||||
player.pause()
|
player.pause()
|
||||||
|
|
@ -2173,6 +2209,7 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func lockTapped() {
|
@objc private func lockTapped() {
|
||||||
|
resetControlsInactivityTimer()
|
||||||
controlsLocked.toggle()
|
controlsLocked.toggle()
|
||||||
|
|
||||||
isControlsVisible = !controlsLocked
|
isControlsVisible = !controlsLocked
|
||||||
|
|
@ -2234,6 +2271,7 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func skipIntro() {
|
@objc private func skipIntro() {
|
||||||
|
resetControlsInactivityTimer()
|
||||||
if let range = skipIntervals.op {
|
if let range = skipIntervals.op {
|
||||||
player.seek(to: range.end)
|
player.seek(to: range.end)
|
||||||
skipIntroDismissedInSession = true
|
skipIntroDismissedInSession = true
|
||||||
|
|
@ -2252,6 +2290,7 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func skipOutro() {
|
@objc private func skipOutro() {
|
||||||
|
resetControlsInactivityTimer()
|
||||||
if let range = skipIntervals.ed {
|
if let range = skipIntervals.ed {
|
||||||
player.seek(to: range.end)
|
player.seek(to: range.end)
|
||||||
skipOutroDismissedInSession = true
|
skipOutroDismissedInSession = true
|
||||||
|
|
@ -2292,11 +2331,13 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func skip85Tapped() {
|
@objc func skip85Tapped() {
|
||||||
|
resetControlsInactivityTimer()
|
||||||
currentTimeVal = min(currentTimeVal + 85, duration)
|
currentTimeVal = min(currentTimeVal + 85, duration)
|
||||||
player.seek(to: CMTime(seconds: currentTimeVal, preferredTimescale: 600))
|
player.seek(to: CMTime(seconds: currentTimeVal, preferredTimescale: 600))
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func dimTapped() {
|
@objc private func dimTapped() {
|
||||||
|
resetControlsInactivityTimer()
|
||||||
isDimmed.toggle()
|
isDimmed.toggle()
|
||||||
dimButtonTimer?.invalidate()
|
dimButtonTimer?.invalidate()
|
||||||
UIView.animate(withDuration: 0.25) {
|
UIView.animate(withDuration: 0.25) {
|
||||||
|
|
@ -3024,6 +3065,8 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
let translation = gesture.translation(in: view)
|
let translation = gesture.translation(in: view)
|
||||||
|
|
||||||
switch gesture.state {
|
switch gesture.state {
|
||||||
|
case .began:
|
||||||
|
resetControlsInactivityTimer()
|
||||||
case .ended:
|
case .ended:
|
||||||
if translation.y > 100 {
|
if translation.y > 100 {
|
||||||
dismiss(animated: true, completion: nil)
|
dismiss(animated: true, completion: nil)
|
||||||
|
|
@ -3543,7 +3586,7 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
pipButton.centerYAnchor.constraint(equalTo: dimButton.centerYAnchor),
|
pipButton.centerYAnchor.constraint(equalTo: dimButton.centerYAnchor),
|
||||||
pipButton.trailingAnchor.constraint(equalTo: dimButton.leadingAnchor, constant: -8),
|
pipButton.trailingAnchor.constraint(equalTo: dimButton.leadingAnchor, constant: -8),
|
||||||
pipButton.widthAnchor.constraint(equalToConstant: 24),
|
pipButton.widthAnchor.constraint(equalToConstant: 30),
|
||||||
pipButton.heightAnchor.constraint(equalToConstant: 24),
|
pipButton.heightAnchor.constraint(equalToConstant: 24),
|
||||||
airplayButton.centerYAnchor.constraint(equalTo: pipButton.centerYAnchor),
|
airplayButton.centerYAnchor.constraint(equalTo: pipButton.centerYAnchor),
|
||||||
airplayButton.trailingAnchor.constraint(equalTo: pipButton.leadingAnchor, constant: -4),
|
airplayButton.trailingAnchor.constraint(equalTo: pipButton.leadingAnchor, constant: -4),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue