Close current video (fixes #15)

This commit is contained in:
Arkadiusz Fal 2021-12-02 21:19:10 +01:00
parent dd995105b5
commit 19b146c6ad
4 changed files with 26 additions and 2 deletions

View File

@ -233,7 +233,7 @@ final class PlayerModel: ObservableObject {
loadCompositionAsset(stream.videoAsset, stream: stream, type: .video, of: video, preservingTime: preservingTime) loadCompositionAsset(stream.videoAsset, stream: stream, type: .video, of: video, preservingTime: preservingTime)
} }
func loadCompositionAsset( private func loadCompositionAsset(
_ asset: AVURLAsset, _ asset: AVURLAsset,
stream: Stream, stream: Stream,
type: AVMediaType, type: AVMediaType,
@ -517,4 +517,10 @@ final class PlayerModel: ObservableObject {
return "\(formatter.string(from: NSNumber(value: rate))!)×" return "\(formatter.string(from: NSNumber(value: rate))!)×"
} }
func closeCurrentItem() {
addCurrentItemToHistory()
currentItem = nil
player.replaceCurrentItem(with: nil)
}
} }

View File

@ -133,6 +133,17 @@ struct VideoDetails: View {
.onAppear { .onAppear {
currentPage = .details currentPage = .details
} }
.contextMenu {
Button {
player.closeCurrentItem()
if !sidebarQueue {
currentPage = .queue
}
} label: {
Label("Close Video", systemImage: "xmark.circle")
}
.disabled(player.currentItem.isNil)
}
.font(.title2.bold()) .font(.title2.bold())
} else { } else {

View File

@ -33,6 +33,13 @@ struct NowPlayingView: View {
} label: { } label: {
VideoBanner(video: item.video) VideoBanner(video: item.video)
} }
.contextMenu {
Button("Close Video") {
player.closeCurrentItem()
}
Button("Cancel", role: .cancel) {}
}
} }
.onPlayPauseCommand(perform: player.togglePlay) .onPlayPauseCommand(perform: player.togglePlay)
} }

View File

@ -3,8 +3,8 @@ import SwiftUI
struct TVNavigationView: View { struct TVNavigationView: View {
@EnvironmentObject<AccountsModel> private var accounts @EnvironmentObject<AccountsModel> private var accounts
@EnvironmentObject<PlayerModel> private var player
@EnvironmentObject<NavigationModel> private var navigation @EnvironmentObject<NavigationModel> private var navigation
@EnvironmentObject<PlayerModel> private var player
@EnvironmentObject<RecentsModel> private var recents @EnvironmentObject<RecentsModel> private var recents
@EnvironmentObject<SearchModel> private var search @EnvironmentObject<SearchModel> private var search