mirror of
https://github.com/yattee/yattee.git
synced 2025-04-27 15:30:33 +05:30
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 playerModel: PlayerModel!
|
||||||
var playerViewController = AVPlayerViewController()
|
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) {
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
super.viewWillAppear(animated)
|
super.viewWillAppear(animated)
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import Foundation
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct VideoPlayerSizeModifier: ViewModifier {
|
struct VideoPlayerSizeModifier: ViewModifier {
|
||||||
let geometry: GeometryProxy!
|
let geometry: GeometryProxy
|
||||||
let aspectRatio: Double?
|
let aspectRatio: Double?
|
||||||
let minimumHeightLeft: Double
|
let minimumHeightLeft: Double
|
||||||
|
|
||||||
@ -11,7 +11,7 @@ struct VideoPlayerSizeModifier: ViewModifier {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
init(
|
init(
|
||||||
geometry: GeometryProxy? = nil,
|
geometry: GeometryProxy,
|
||||||
aspectRatio: Double? = nil,
|
aspectRatio: Double? = nil,
|
||||||
minimumHeightLeft: Double? = nil
|
minimumHeightLeft: Double? = nil
|
||||||
) {
|
) {
|
||||||
@ -21,15 +21,10 @@ struct VideoPlayerSizeModifier: ViewModifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func body(content: Content) -> some View {
|
func body(content: Content) -> some View {
|
||||||
// TODO: verify if optional GeometryProxy is still used
|
content
|
||||||
if geometry != nil {
|
.frame(maxHeight: maxHeight)
|
||||||
content
|
.aspectRatio(usedAspectRatio, contentMode: usedAspectRatioContentMode)
|
||||||
.frame(maxHeight: maxHeight)
|
.edgesIgnoringSafeArea(edgesIgnoringSafeArea)
|
||||||
.aspectRatio(usedAspectRatio, contentMode: usedAspectRatioContentMode)
|
|
||||||
.edgesIgnoringSafeArea(edgesIgnoringSafeArea)
|
|
||||||
} else {
|
|
||||||
content.edgesIgnoringSafeArea(edgesIgnoringSafeArea)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var usedAspectRatio: Double {
|
var usedAspectRatio: Double {
|
||||||
|
@ -67,11 +67,11 @@ struct VideoPlayerView: View {
|
|||||||
} else {
|
} else {
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
Player()
|
Player()
|
||||||
.modifier(VideoPlayerSizeModifier(geometry: geometry))
|
.modifier(VideoPlayerSizeModifier(geometry: geometry, aspectRatio: player.controller?.aspectRatio))
|
||||||
|
|
||||||
#else
|
#else
|
||||||
player.playerView
|
player.playerView
|
||||||
.modifier(VideoPlayerSizeModifier(geometry: geometry))
|
.modifier(VideoPlayerSizeModifier(geometry: geometry, aspectRatio: player.controller?.aspectRatio))
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,7 +99,7 @@ struct VideoPlayerView: View {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
.background()
|
.background()
|
||||||
.modifier(VideoDetailsPaddingModifier(geometry: geometry, fullScreen: fullScreen))
|
.modifier(VideoDetailsPaddingModifier(geometry: geometry, aspectRatio: player.controller?.aspectRatio, fullScreen: fullScreen))
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,16 @@ final class PlayerViewController: NSViewController {
|
|||||||
var playerView = AVPlayerView()
|
var playerView = AVPlayerView()
|
||||||
var pictureInPictureDelegate = PictureInPictureDelegate()
|
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() {
|
override func viewDidDisappear() {
|
||||||
super.viewDidDisappear()
|
super.viewDidDisappear()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user