mirror of
https://github.com/yattee/yattee.git
synced 2024-11-09 15:58:20 +00:00
Change player size based on aspect ratio
This commit is contained in:
parent
f33319fd64
commit
76f0a1c66c
@ -8,6 +8,16 @@ final class PlayerViewController: UIViewController {
|
||||
var playerModel: PlayerModel!
|
||||
var playerViewController = AVPlayerViewController()
|
||||
|
||||
var aspectRatio: Double? {
|
||||
let ratio = Double(playerViewController.videoBounds.width) / Double(playerViewController.videoBounds.height)
|
||||
|
||||
if !ratio.isFinite {
|
||||
return VideoPlayerView.defaultAspectRatio
|
||||
}
|
||||
|
||||
return [ratio, 1.0].max()!
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
|
||||
|
@ -2,7 +2,7 @@ import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct VideoPlayerSizeModifier: ViewModifier {
|
||||
let geometry: GeometryProxy!
|
||||
let geometry: GeometryProxy
|
||||
let aspectRatio: Double?
|
||||
let minimumHeightLeft: Double
|
||||
|
||||
@ -11,7 +11,7 @@ struct VideoPlayerSizeModifier: ViewModifier {
|
||||
#endif
|
||||
|
||||
init(
|
||||
geometry: GeometryProxy? = nil,
|
||||
geometry: GeometryProxy,
|
||||
aspectRatio: Double? = nil,
|
||||
minimumHeightLeft: Double? = nil
|
||||
) {
|
||||
@ -21,15 +21,10 @@ struct VideoPlayerSizeModifier: ViewModifier {
|
||||
}
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
// TODO: verify if optional GeometryProxy is still used
|
||||
if geometry != nil {
|
||||
content
|
||||
.frame(maxHeight: maxHeight)
|
||||
.aspectRatio(usedAspectRatio, contentMode: usedAspectRatioContentMode)
|
||||
.edgesIgnoringSafeArea(edgesIgnoringSafeArea)
|
||||
} else {
|
||||
content.edgesIgnoringSafeArea(edgesIgnoringSafeArea)
|
||||
}
|
||||
content
|
||||
.frame(maxHeight: maxHeight)
|
||||
.aspectRatio(usedAspectRatio, contentMode: usedAspectRatioContentMode)
|
||||
.edgesIgnoringSafeArea(edgesIgnoringSafeArea)
|
||||
}
|
||||
|
||||
var usedAspectRatio: Double {
|
||||
|
@ -67,11 +67,11 @@ struct VideoPlayerView: View {
|
||||
} else {
|
||||
#if os(macOS)
|
||||
Player()
|
||||
.modifier(VideoPlayerSizeModifier(geometry: geometry))
|
||||
.modifier(VideoPlayerSizeModifier(geometry: geometry, aspectRatio: player.controller?.aspectRatio))
|
||||
|
||||
#else
|
||||
player.playerView
|
||||
.modifier(VideoPlayerSizeModifier(geometry: geometry))
|
||||
.modifier(VideoPlayerSizeModifier(geometry: geometry, aspectRatio: player.controller?.aspectRatio))
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -99,7 +99,7 @@ struct VideoPlayerView: View {
|
||||
#endif
|
||||
}
|
||||
.background()
|
||||
.modifier(VideoDetailsPaddingModifier(geometry: geometry, fullScreen: fullScreen))
|
||||
.modifier(VideoDetailsPaddingModifier(geometry: geometry, aspectRatio: player.controller?.aspectRatio, fullScreen: fullScreen))
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -6,6 +6,16 @@ final class PlayerViewController: NSViewController {
|
||||
var playerView = AVPlayerView()
|
||||
var pictureInPictureDelegate = PictureInPictureDelegate()
|
||||
|
||||
var aspectRatio: Double? {
|
||||
let ratio = Double(playerView.videoBounds.width) / Double(playerView.videoBounds.height)
|
||||
|
||||
if !ratio.isFinite {
|
||||
return VideoPlayerView.defaultAspectRatio
|
||||
}
|
||||
|
||||
return [ratio, 1.0].max()!
|
||||
}
|
||||
|
||||
override func viewDidDisappear() {
|
||||
super.viewDidDisappear()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user