mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
PiP improvements
This commit is contained in:
@@ -132,21 +132,29 @@ struct ContentView: View {
|
||||
|
||||
@ViewBuilder var videoPlayer: some View {
|
||||
if player.presentingPlayer {
|
||||
VideoPlayerView()
|
||||
.environmentObject(accounts)
|
||||
.environmentObject(comments)
|
||||
.environmentObject(instances)
|
||||
.environmentObject(navigation)
|
||||
.environmentObject(player)
|
||||
.environmentObject(playerControls)
|
||||
.environmentObject(playlists)
|
||||
.environmentObject(recents)
|
||||
.environmentObject(subscriptions)
|
||||
.environmentObject(thumbnailsModel)
|
||||
.environment(\.navigationStyle, navigationStyle)
|
||||
playerView
|
||||
.transition(.move(edge: .bottom))
|
||||
} else if player.activeBackend == .appleAVPlayer {
|
||||
#if os(iOS)
|
||||
playerView.offset(y: UIScreen.main.bounds.height)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
var playerView: some View {
|
||||
VideoPlayerView()
|
||||
.environmentObject(accounts)
|
||||
.environmentObject(comments)
|
||||
.environmentObject(instances)
|
||||
.environmentObject(navigation)
|
||||
.environmentObject(player)
|
||||
.environmentObject(playerControls)
|
||||
.environmentObject(playlists)
|
||||
.environmentObject(recents)
|
||||
.environmentObject(subscriptions)
|
||||
.environmentObject(thumbnailsModel)
|
||||
.environment(\.navigationStyle, navigationStyle)
|
||||
}
|
||||
}
|
||||
|
||||
struct ContentView_Previews: PreviewProvider {
|
||||
|
@@ -6,8 +6,9 @@ struct AppleAVPlayerView: UIViewRepresentable {
|
||||
@EnvironmentObject<PlayerModel> private var player
|
||||
|
||||
func makeUIView(context _: Context) -> some UIView {
|
||||
player.playerLayerView = PlayerLayerView(frame: .zero)
|
||||
return player.playerLayerView
|
||||
let playerLayerView = PlayerLayerView(frame: .zero)
|
||||
playerLayerView.player = player
|
||||
return playerLayerView
|
||||
}
|
||||
|
||||
func updateUIView(_: UIViewType, context _: Context) {}
|
||||
|
@@ -227,8 +227,8 @@ struct PlayerControls: View {
|
||||
HStack(spacing: 20) {
|
||||
fullscreenButton
|
||||
|
||||
pipButton
|
||||
#if os(iOS)
|
||||
pipButton
|
||||
lockOrientationButton
|
||||
#endif
|
||||
|
||||
|
@@ -15,17 +15,6 @@ struct PlayerBackendView: View {
|
||||
player.mpvPlayerView
|
||||
case .appleAVPlayer:
|
||||
player.avPlayerView
|
||||
#if os(iOS)
|
||||
.onAppear {
|
||||
player.pipController = .init(playerLayer: player.playerLayerView.playerLayer)
|
||||
let pipDelegate = PiPDelegate()
|
||||
pipDelegate.player = player
|
||||
|
||||
player.pipDelegate = pipDelegate
|
||||
player.pipController?.delegate = pipDelegate
|
||||
player.playerLayerView.playerLayer.player = player.avPlayerBackend.avPlayer
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
.overlay(GeometryReader { proxy in
|
||||
|
@@ -1,23 +1,51 @@
|
||||
import AVFoundation
|
||||
import Foundation
|
||||
import UIKit
|
||||
#if os(macOS)
|
||||
import AppKit
|
||||
#else
|
||||
import UIKit
|
||||
#endif
|
||||
|
||||
final class PlayerLayerView: UIView {
|
||||
var playerLayer = AVPlayerLayer()
|
||||
#if os(macOS)
|
||||
final class PlayerLayerView: NSView {
|
||||
var player: PlayerModel! { didSet {
|
||||
wantsLayer = true
|
||||
}}
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
override init(frame frameRect: NSRect) {
|
||||
super.init(frame: frameRect)
|
||||
}
|
||||
|
||||
layer.addSublayer(playerLayer)
|
||||
override func makeBackingLayer() -> CALayer {
|
||||
player.avPlayerBackend.playerLayer
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
}
|
||||
}
|
||||
#else
|
||||
final class PlayerLayerView: UIView {
|
||||
var player: PlayerModel!
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder _: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
}
|
||||
|
||||
override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
playerLayer.frame = bounds
|
||||
private var layerAdded = false
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder _: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func layoutSubviews() {
|
||||
if !layerAdded {
|
||||
layerAdded = true
|
||||
layer.addSublayer(player.avPlayerBackend.playerLayer)
|
||||
}
|
||||
player.avPlayerBackend.playerLayer.frame = bounds
|
||||
super.layoutSubviews()
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@@ -33,7 +33,9 @@ struct VideoDetails: View {
|
||||
@StateObject private var page: Page = .first()
|
||||
|
||||
@Environment(\.navigationStyle) private var navigationStyle
|
||||
@Environment(\.verticalSizeClass) private var verticalSizeClass
|
||||
#if os(iOS)
|
||||
@Environment(\.verticalSizeClass) private var verticalSizeClass
|
||||
#endif
|
||||
|
||||
@EnvironmentObject<AccountsModel> private var accounts
|
||||
@EnvironmentObject<CommentsModel> private var comments
|
||||
@@ -227,7 +229,9 @@ struct VideoDetails: View {
|
||||
.redacted(reason: .placeholder)
|
||||
} else if video.description != nil, !video.description!.isEmpty {
|
||||
VideoDescription(video: video, detailsSize: detailsSize)
|
||||
#if os(iOS)
|
||||
.padding(.bottom, fullScreenLayout ? 10 : SafeArea.insets.bottom)
|
||||
#endif
|
||||
} else {
|
||||
Text("No description")
|
||||
.foregroundColor(.secondary)
|
||||
|
@@ -245,14 +245,14 @@ struct VideoPlayerView: View {
|
||||
ZStack(alignment: .bottomLeading) {
|
||||
#if os(tvOS)
|
||||
ZStack {
|
||||
PlayerBackendView()
|
||||
player.playerBackendView
|
||||
|
||||
tvControls
|
||||
}
|
||||
.ignoresSafeArea()
|
||||
#else
|
||||
GeometryReader { geometry in
|
||||
PlayerBackendView()
|
||||
player.playerBackendView
|
||||
#if !os(tvOS)
|
||||
.modifier(
|
||||
VideoPlayerSizeModifier(
|
||||
|
@@ -59,10 +59,8 @@ struct VideoContextMenuView: View {
|
||||
|
||||
Section {
|
||||
playNowButton
|
||||
#if os(iOS)
|
||||
playNowInPictureInPictureButton
|
||||
#endif
|
||||
#if !os(tvOS)
|
||||
playNowInPictureInPictureButton
|
||||
playNowInMusicMode
|
||||
#endif
|
||||
}
|
||||
@@ -169,7 +167,8 @@ struct VideoContextMenuView: View {
|
||||
|
||||
private var playNowInPictureInPictureButton: some View {
|
||||
Button {
|
||||
player.controls.startPiP(startImmediately: false)
|
||||
player.controls.startPiP(startImmediately: player.presentingPlayer && player.activeBackend == .appleAVPlayer)
|
||||
player.hide()
|
||||
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
||||
player.play(video, at: watch?.timeToRestart, showingPlayer: false)
|
||||
|
Reference in New Issue
Block a user