1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 22:00:31 +05:30

Add setting "Close player when closing video"

This commit is contained in:
Arkadiusz Fal 2022-08-07 13:15:27 +02:00
parent d0e3839040
commit 8e2c30bf00
6 changed files with 26 additions and 15 deletions

View File

@ -150,6 +150,7 @@ final class PlayerModel: ObservableObject {
#if !os(macOS) #if !os(macOS)
@Default(.closePiPAndOpenPlayerOnEnteringForeground) var closePiPAndOpenPlayerOnEnteringForeground @Default(.closePiPAndOpenPlayerOnEnteringForeground) var closePiPAndOpenPlayerOnEnteringForeground
@Default(.closePlayerOnItemClose) private var closePlayerOnItemClose
#endif #endif
private var currentArtwork: MPMediaItemArtwork? private var currentArtwork: MPMediaItemArtwork?
@ -524,12 +525,23 @@ final class PlayerModel: ObservableObject {
} }
func closeCurrentItem(finished: Bool = false) { func closeCurrentItem(finished: Bool = false) {
pause()
prepareCurrentItemForHistory(finished: finished) prepareCurrentItemForHistory(finished: finished)
currentItem = nil currentItem = nil
backend.closeItem() backend.closeItem()
aspectRatio = VideoPlayerView.defaultAspectRatio aspectRatio = VideoPlayerView.defaultAspectRatio
resetAutoplay() resetAutoplay()
closePiP()
exitFullScreen()
#if !os(macOS)
if closePlayerOnItemClose {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { [weak self] in self?.hide() }
}
#endif
} }
func closePiP() { func closePiP() {

View File

@ -63,6 +63,7 @@ extension Defaults.Keys {
static let pauseOnEnteringBackground = Key<Bool>("pauseOnEnteringBackground", default: true) static let pauseOnEnteringBackground = Key<Bool>("pauseOnEnteringBackground", default: true)
#endif #endif
static let closeLastItemOnPlaybackEnd = Key<Bool>("closeLastItemOnPlaybackEnd", default: false) static let closeLastItemOnPlaybackEnd = Key<Bool>("closeLastItemOnPlaybackEnd", default: false)
static let closePlayerOnItemClose = Key<Bool>("closePlayerOnItemClose", default: false)
static let closePiPOnNavigation = Key<Bool>("closePiPOnNavigation", default: false) static let closePiPOnNavigation = Key<Bool>("closePiPOnNavigation", default: false)
static let closePiPOnOpeningPlayer = Key<Bool>("closePiPOnOpeningPlayer", default: false) static let closePiPOnOpeningPlayer = Key<Bool>("closePiPOnOpeningPlayer", default: false)

View File

@ -23,6 +23,10 @@ struct PlayerControls: View {
@FocusState private var focusedField: Field? @FocusState private var focusedField: Field?
#endif #endif
#if !os(macOS)
@Default(.closePlayerOnItemClose) private var closePlayerOnItemClose
#endif
init(player: PlayerModel, thumbnails: ThumbnailsModel) { init(player: PlayerModel, thumbnails: ThumbnailsModel) {
self.player = player self.player = player
self.thumbnails = thumbnails self.thumbnails = thumbnails
@ -242,18 +246,7 @@ struct PlayerControls: View {
private var closeVideoButton: some View { private var closeVideoButton: some View {
button("Close", systemImage: "xmark") { button("Close", systemImage: "xmark") {
player.pause() player.closeCurrentItem()
player.hide()
player.closePiP()
var delay = 0.2
#if os(macOS)
delay = 0.0
#endif
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
player.closeCurrentItem()
}
} }
} }

View File

@ -299,7 +299,7 @@ struct VideoPlayerView: View {
@ViewBuilder var playerPlaceholder: some View { @ViewBuilder var playerPlaceholder: some View {
if player.currentItem.isNil { if player.currentItem.isNil {
ZStack(alignment: .topLeading) { ZStack(alignment: .topTrailing) {
HStack { HStack {
Spacer() Spacer()
VStack { VStack {

View File

@ -18,6 +18,7 @@ struct PlayerSettings: View {
@Default(.closePiPOnNavigation) private var closePiPOnNavigation @Default(.closePiPOnNavigation) private var closePiPOnNavigation
@Default(.closePiPOnOpeningPlayer) private var closePiPOnOpeningPlayer @Default(.closePiPOnOpeningPlayer) private var closePiPOnOpeningPlayer
#if !os(macOS) #if !os(macOS)
@Default(.closePlayerOnItemClose) private var closePlayerOnItemClose
@Default(.pauseOnEnteringBackground) private var pauseOnEnteringBackground @Default(.pauseOnEnteringBackground) private var pauseOnEnteringBackground
@Default(.closePiPAndOpenPlayerOnEnteringForeground) private var closePiPAndOpenPlayerOnEnteringForeground @Default(.closePiPAndOpenPlayerOnEnteringForeground) private var closePiPAndOpenPlayerOnEnteringForeground
#endif #endif
@ -61,6 +62,7 @@ struct PlayerSettings: View {
pauseOnHidingPlayerToggle pauseOnHidingPlayerToggle
#if !os(macOS) #if !os(macOS)
pauseOnEnteringBackgroundToogle pauseOnEnteringBackgroundToogle
closePlayerOnItemCloseToggle
#endif #endif
closeLastItemOnPlaybackEndToggle closeLastItemOnPlaybackEndToggle
systemControlsCommandsPicker systemControlsCommandsPicker
@ -175,6 +177,10 @@ struct PlayerSettings: View {
private var pauseOnEnteringBackgroundToogle: some View { private var pauseOnEnteringBackgroundToogle: some View {
Toggle("Pause when entering background", isOn: $pauseOnEnteringBackground) Toggle("Pause when entering background", isOn: $pauseOnEnteringBackground)
} }
private var closePlayerOnItemCloseToggle: some View {
Toggle("Close player when closing video", isOn: $closePlayerOnItemClose)
}
#endif #endif
private var closeLastItemOnPlaybackEndToggle: some View { private var closeLastItemOnPlaybackEndToggle: some View {
@ -207,7 +213,7 @@ struct PlayerSettings: View {
#endif #endif
} }
struct PlaybackSettings_Previews: PreviewProvider { struct PlayerSettings_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
VStack(alignment: .leading) { VStack(alignment: .leading) {
PlayerSettings() PlayerSettings()

View File

@ -113,7 +113,6 @@ struct ControlsBar: View {
Button { Button {
model.closeCurrentItem() model.closeCurrentItem()
model.closePiP()
} label: { } label: {
Label("Close Video", systemImage: "xmark") Label("Close Video", systemImage: "xmark")
.padding(.vertical, 10) .padding(.vertical, 10)