mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
Add Open in PiP option (fix #137)
This commit is contained in:
@@ -265,25 +265,7 @@ struct PlayerControls: View {
|
||||
|
||||
private var pipButton: some View {
|
||||
button("PiP", systemImage: "pip") {
|
||||
if player.activeBackend == .mpv {
|
||||
player.avPlayerBackend.switchToMPVOnPipClose = true
|
||||
}
|
||||
|
||||
#if !os(macOS)
|
||||
player.exitFullScreen()
|
||||
#endif
|
||||
|
||||
if player.activeBackend != PlayerBackendType.appleAVPlayer {
|
||||
player.saveTime {
|
||||
player.changeActiveBackend(from: .mpv, to: .appleAVPlayer)
|
||||
}
|
||||
}
|
||||
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
|
||||
print(player.pipController?.isPictureInPicturePossible ?? false ? "possible" : "NOT possible")
|
||||
player.avPlayerBackend.startPictureInPictureOnPlay = true
|
||||
player.pipController?.startPictureInPicture()
|
||||
}
|
||||
model.startPiP()
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import CoreData
|
||||
import CoreMedia
|
||||
import Defaults
|
||||
import SwiftUI
|
||||
|
||||
@@ -53,6 +54,9 @@ struct VideoContextMenuView: View {
|
||||
|
||||
Section {
|
||||
playNowButton
|
||||
#if os(iOS)
|
||||
playNowInPictureInPictureButton
|
||||
#endif
|
||||
}
|
||||
|
||||
Section {
|
||||
@@ -133,6 +137,26 @@ struct VideoContextMenuView: View {
|
||||
}
|
||||
}
|
||||
|
||||
private var playNowInPictureInPictureButton: some View {
|
||||
Button {
|
||||
player.controls.startPiP(startImmediately: false)
|
||||
|
||||
var time: CMTime?
|
||||
if saveHistory,
|
||||
let stoppedAt = watch?.stoppedAt,
|
||||
!watch!.finished
|
||||
{
|
||||
time = .secondsInDefaultTimescale(stoppedAt)
|
||||
}
|
||||
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
||||
player.play(video, at: time, showingPlayer: false)
|
||||
}
|
||||
} label: {
|
||||
Label("Play in PiP", systemImage: "pip")
|
||||
}
|
||||
}
|
||||
|
||||
private var playNextButton: some View {
|
||||
Button {
|
||||
player.playNext(video)
|
||||
|
Reference in New Issue
Block a user