mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 21:43:41 +00:00
Controls updates fixes
This commit is contained in:
parent
711208d9b7
commit
5f50797b54
@ -1,6 +1,7 @@
|
|||||||
import AVFoundation
|
import AVFoundation
|
||||||
import Defaults
|
import Defaults
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import Logging
|
||||||
import MediaPlayer
|
import MediaPlayer
|
||||||
#if !os(macOS)
|
#if !os(macOS)
|
||||||
import UIKit
|
import UIKit
|
||||||
@ -9,6 +10,8 @@ import MediaPlayer
|
|||||||
final class AVPlayerBackend: PlayerBackend {
|
final class AVPlayerBackend: PlayerBackend {
|
||||||
static let assetKeysToLoad = ["tracks", "playable", "duration"]
|
static let assetKeysToLoad = ["tracks", "playable", "duration"]
|
||||||
|
|
||||||
|
private var logger = Logger(label: "avplayer-backend")
|
||||||
|
|
||||||
var model: PlayerModel!
|
var model: PlayerModel!
|
||||||
var controls: PlayerControlsModel!
|
var controls: PlayerControlsModel!
|
||||||
var playerTime: PlayerTimeModel!
|
var playerTime: PlayerTimeModel!
|
||||||
@ -69,7 +72,7 @@ final class AVPlayerBackend: PlayerBackend {
|
|||||||
|
|
||||||
private var timeObserverThrottle = Throttle(interval: 2)
|
private var timeObserverThrottle = Throttle(interval: 2)
|
||||||
|
|
||||||
private var controlsUpdates = false
|
internal var controlsUpdates = false
|
||||||
|
|
||||||
init(model: PlayerModel, controls: PlayerControlsModel?, playerTime: PlayerTimeModel?) {
|
init(model: PlayerModel, controls: PlayerControlsModel?, playerTime: PlayerTimeModel?) {
|
||||||
self.model = model
|
self.model = model
|
||||||
@ -589,6 +592,11 @@ final class AVPlayerBackend: PlayerBackend {
|
|||||||
func updateControls() {}
|
func updateControls() {}
|
||||||
|
|
||||||
func startControlsUpdates() {
|
func startControlsUpdates() {
|
||||||
|
guard model.presentingPlayer, model.controls.presentingControls, !model.controls.presentingOverlays else {
|
||||||
|
logger.info("ignored controls update start")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
logger.info("starting controls updates")
|
||||||
controlsUpdates = true
|
controlsUpdates = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ final class MPVBackend: PlayerBackend {
|
|||||||
|
|
||||||
private var onFileLoaded: (() -> Void)?
|
private var onFileLoaded: (() -> Void)?
|
||||||
|
|
||||||
private var controlsUpdates = false
|
internal var controlsUpdates = false
|
||||||
private var timeObserverThrottle = Throttle(interval: 2)
|
private var timeObserverThrottle = Throttle(interval: 2)
|
||||||
|
|
||||||
var tracks: Int {
|
var tracks: Int {
|
||||||
@ -337,7 +337,7 @@ final class MPVBackend: PlayerBackend {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
DispatchQueue.main.async { [weak self] in
|
DispatchQueue.main.async(qos: .userInteractive) { [weak self] in
|
||||||
guard let self = self else {
|
guard let self = self else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ protocol PlayerBackend {
|
|||||||
var playerItemDuration: CMTime? { get }
|
var playerItemDuration: CMTime? { get }
|
||||||
|
|
||||||
var aspectRatio: Double { get }
|
var aspectRatio: Double { get }
|
||||||
|
var controlsUpdates: Bool { get }
|
||||||
|
|
||||||
func bestPlayable(_ streams: [Stream], maxResolution: ResolutionSetting) -> Stream?
|
func bestPlayable(_ streams: [Stream], maxResolution: ResolutionSetting) -> Stream?
|
||||||
func canPlay(_ stream: Stream) -> Bool
|
func canPlay(_ stream: Stream) -> Bool
|
||||||
|
@ -39,14 +39,20 @@ final class PlayerControlsModel: ObservableObject {
|
|||||||
func handlePresentationChange() {
|
func handlePresentationChange() {
|
||||||
guard let player = player else { return }
|
guard let player = player else { return }
|
||||||
if presentingControls {
|
if presentingControls {
|
||||||
player.backend.startControlsUpdates()
|
DispatchQueue.main.async(qos: .userInteractive) { [weak self] in
|
||||||
resetTimer()
|
player.backend.startControlsUpdates()
|
||||||
|
self?.resetTimer()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if !player.musicMode {
|
if !player.musicMode {
|
||||||
player.backend.stopControlsUpdates()
|
DispatchQueue.main.async(qos: .userInteractive) { [weak self] in
|
||||||
removeTimer()
|
player.backend.stopControlsUpdates()
|
||||||
|
self?.removeTimer()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
presentingControls = true
|
DispatchQueue.main.async(qos: .userInteractive) { [weak self] in
|
||||||
|
self?.presentingControls = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,7 +122,6 @@ final class PlayerControlsModel: ObservableObject {
|
|||||||
timer = Timer.scheduledTimer(withTimeInterval: 5.0, repeats: false) { _ in
|
timer = Timer.scheduledTimer(withTimeInterval: 5.0, repeats: false) { _ in
|
||||||
withAnimation(PlayerControls.animation) { [weak self] in
|
withAnimation(PlayerControls.animation) { [weak self] in
|
||||||
self?.presentingControls = false
|
self?.presentingControls = false
|
||||||
self?.player.backend.stopControlsUpdates()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,9 +23,9 @@ struct TimelineView: View {
|
|||||||
@State private var size = CGSize.zero
|
@State private var size = CGSize.zero
|
||||||
@State private var tooltipSize = CGSize.zero
|
@State private var tooltipSize = CGSize.zero
|
||||||
@State private var dragging = false { didSet {
|
@State private var dragging = false { didSet {
|
||||||
if dragging {
|
if dragging, player.backend.controlsUpdates {
|
||||||
player.backend.stopControlsUpdates()
|
player.backend.stopControlsUpdates()
|
||||||
} else {
|
} else if !dragging, !player.backend.controlsUpdates {
|
||||||
player.backend.startControlsUpdates()
|
player.backend.startControlsUpdates()
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
Loading…
Reference in New Issue
Block a user