1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 22:00:31 +05:30

Controls updates fixes

This commit is contained in:
Arkadiusz Fal 2022-08-23 23:29:50 +02:00
parent 711208d9b7
commit 5f50797b54
5 changed files with 25 additions and 11 deletions

View File

@ -1,6 +1,7 @@
import AVFoundation
import Defaults
import Foundation
import Logging
import MediaPlayer
#if !os(macOS)
import UIKit
@ -9,6 +10,8 @@ import MediaPlayer
final class AVPlayerBackend: PlayerBackend {
static let assetKeysToLoad = ["tracks", "playable", "duration"]
private var logger = Logger(label: "avplayer-backend")
var model: PlayerModel!
var controls: PlayerControlsModel!
var playerTime: PlayerTimeModel!
@ -69,7 +72,7 @@ final class AVPlayerBackend: PlayerBackend {
private var timeObserverThrottle = Throttle(interval: 2)
private var controlsUpdates = false
internal var controlsUpdates = false
init(model: PlayerModel, controls: PlayerControlsModel?, playerTime: PlayerTimeModel?) {
self.model = model
@ -589,6 +592,11 @@ final class AVPlayerBackend: PlayerBackend {
func updateControls() {}
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
}

View File

@ -89,7 +89,7 @@ final class MPVBackend: PlayerBackend {
private var onFileLoaded: (() -> Void)?
private var controlsUpdates = false
internal var controlsUpdates = false
private var timeObserverThrottle = Throttle(interval: 2)
var tracks: Int {
@ -337,7 +337,7 @@ final class MPVBackend: PlayerBackend {
return
}
DispatchQueue.main.async { [weak self] in
DispatchQueue.main.async(qos: .userInteractive) { [weak self] in
guard let self = self else {
return
}

View File

@ -20,6 +20,7 @@ protocol PlayerBackend {
var playerItemDuration: CMTime? { get }
var aspectRatio: Double { get }
var controlsUpdates: Bool { get }
func bestPlayable(_ streams: [Stream], maxResolution: ResolutionSetting) -> Stream?
func canPlay(_ stream: Stream) -> Bool

View File

@ -39,14 +39,20 @@ final class PlayerControlsModel: ObservableObject {
func handlePresentationChange() {
guard let player = player else { return }
if presentingControls {
player.backend.startControlsUpdates()
resetTimer()
DispatchQueue.main.async(qos: .userInteractive) { [weak self] in
player.backend.startControlsUpdates()
self?.resetTimer()
}
} else {
if !player.musicMode {
player.backend.stopControlsUpdates()
removeTimer()
DispatchQueue.main.async(qos: .userInteractive) { [weak self] in
player.backend.stopControlsUpdates()
self?.removeTimer()
}
} 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
withAnimation(PlayerControls.animation) { [weak self] in
self?.presentingControls = false
self?.player.backend.stopControlsUpdates()
}
}
}

View File

@ -23,9 +23,9 @@ struct TimelineView: View {
@State private var size = CGSize.zero
@State private var tooltipSize = CGSize.zero
@State private var dragging = false { didSet {
if dragging {
if dragging, player.backend.controlsUpdates {
player.backend.stopControlsUpdates()
} else {
} else if !dragging, !player.backend.controlsUpdates {
player.backend.startControlsUpdates()
}
}}