mirror of
https://github.com/yattee/yattee.git
synced 2025-08-06 18:54:11 +00:00
Player layout fixes
This commit is contained in:
@@ -33,6 +33,14 @@ final class AVPlayerBackend: PlayerBackend {
|
||||
avPlayer.timeControlStatus == .playing
|
||||
}
|
||||
|
||||
var aspectRatio: Double {
|
||||
#if os(tvOS)
|
||||
VideoPlayerView.defaultAspectRatio
|
||||
#else
|
||||
controller?.aspectRatio ?? VideoPlayerView.defaultAspectRatio
|
||||
#endif
|
||||
}
|
||||
|
||||
var isSeeking: Bool {
|
||||
// TODO: implement this maybe?
|
||||
false
|
||||
@@ -144,14 +152,10 @@ final class AVPlayerBackend: PlayerBackend {
|
||||
}
|
||||
|
||||
func enterFullScreen() {
|
||||
controller?.playerView
|
||||
.perform(NSSelectorFromString("enterFullScreenAnimated:completionHandler:"), with: false, with: nil)
|
||||
model.toggleFullscreen(model?.playingFullScreen ?? false)
|
||||
}
|
||||
|
||||
func exitFullScreen() {
|
||||
controller?.playerView
|
||||
.perform(NSSelectorFromString("exitFullScreenAnimated:completionHandler:"), with: false, with: nil)
|
||||
}
|
||||
func exitFullScreen() {}
|
||||
|
||||
#if os(tvOS)
|
||||
func closePiP(wasPlaying: Bool) {
|
||||
|
@@ -86,6 +86,10 @@ final class MPVBackend: PlayerBackend {
|
||||
client?.tracksCount ?? -1
|
||||
}
|
||||
|
||||
var aspectRatio: Double {
|
||||
client?.aspectRatio ?? VideoPlayerView.defaultAspectRatio
|
||||
}
|
||||
|
||||
var frameDropCount: Int {
|
||||
client?.frameDropCount ?? 0
|
||||
}
|
||||
|
@@ -185,6 +185,20 @@ final class MPVClient: ObservableObject {
|
||||
mpv.isNil ? 0.0 : getDouble("demuxer-cache-duration")
|
||||
}
|
||||
|
||||
var aspectRatio: Double {
|
||||
guard !mpv.isNil else { return VideoPlayerView.defaultAspectRatio }
|
||||
let aspect = getDouble("video-params/aspect")
|
||||
return aspect.isZero ? VideoPlayerView.defaultAspectRatio : aspect
|
||||
}
|
||||
|
||||
var dh: Double {
|
||||
let defaultDh = 500.0
|
||||
guard !mpv.isNil else { return defaultDh }
|
||||
|
||||
let dh = getDouble("video-params/dh")
|
||||
return dh.isZero ? defaultDh : dh
|
||||
}
|
||||
|
||||
var duration: CMTime {
|
||||
CMTime.secondsInDefaultTimescale(mpv.isNil ? -1 : getDouble("duration"))
|
||||
}
|
||||
@@ -240,7 +254,24 @@ final class MPVClient: ObservableObject {
|
||||
return
|
||||
}
|
||||
|
||||
glView?.frame = CGRect(x: 0, y: 0, width: roundedWidth, height: roundedHeight)
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
guard let self = self else { return }
|
||||
UIView.animate(withDuration: 0.2, animations: {
|
||||
let height = [self.backend.model.playerSize.height, self.backend.model.playerSize.width / self.aspectRatio].min()!
|
||||
let offsetY = self.backend.model.playingFullScreen ? ((self.backend.model.playerSize.height / 2.0) - (height / 2)) : 0
|
||||
self.glView?.frame = CGRect(x: 0, y: offsetY, width: roundedWidth, height: height)
|
||||
}) { completion in
|
||||
if completion {
|
||||
self.logger.info("setting player size to \(roundedWidth),\(roundedHeight) FINISHED")
|
||||
|
||||
self.glView?.queue.async {
|
||||
self.glView.display()
|
||||
}
|
||||
self.backend?.controls?.objectWillChange.send()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@@ -19,6 +19,8 @@ protocol PlayerBackend {
|
||||
var isSeeking: Bool { get }
|
||||
var playerItemDuration: CMTime? { get }
|
||||
|
||||
var aspectRatio: Double { get }
|
||||
|
||||
func bestPlayable(_ streams: [Stream], maxResolution: ResolutionSetting) -> Stream?
|
||||
func canPlay(_ stream: Stream) -> Bool
|
||||
|
||||
|
Reference in New Issue
Block a user