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

View File

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

View File

@ -23,6 +23,10 @@ struct PlayerControls: View {
@FocusState private var focusedField: Field?
#endif
#if !os(macOS)
@Default(.closePlayerOnItemClose) private var closePlayerOnItemClose
#endif
init(player: PlayerModel, thumbnails: ThumbnailsModel) {
self.player = player
self.thumbnails = thumbnails
@ -242,20 +246,9 @@ struct PlayerControls: View {
private var closeVideoButton: some View {
button("Close", systemImage: "xmark") {
player.pause()
player.hide()
player.closePiP()
var delay = 0.2
#if os(macOS)
delay = 0.0
#endif
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
player.closeCurrentItem()
}
}
}
private var musicModeButton: some View {
button("Music Mode", systemImage: "music.note", background: false, active: player.musicMode, action: player.toggleMusicMode)

View File

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

View File

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

View File

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