mirror of
https://github.com/yattee/yattee.git
synced 2025-08-05 18:24:02 +00:00
Add related videos
This commit is contained in:
@@ -10,12 +10,12 @@ struct PlayerQueueView: View {
|
||||
List {
|
||||
Group {
|
||||
playingNext
|
||||
related
|
||||
playedPreviously
|
||||
}
|
||||
.padding(.vertical, 5)
|
||||
.listRowInsets(EdgeInsets())
|
||||
#if os(iOS)
|
||||
.padding(.horizontal, 10)
|
||||
#if !os(iOS)
|
||||
.padding(.vertical, 5)
|
||||
.listRowInsets(EdgeInsets())
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -71,7 +71,27 @@ struct PlayerQueueView: View {
|
||||
}
|
||||
}
|
||||
|
||||
func removeButton(_ item: PlayerQueueItem, history: Bool) -> some View {
|
||||
private var related: some View {
|
||||
Group {
|
||||
if !player.currentVideo.isNil, !player.currentVideo!.related.isEmpty {
|
||||
Section(header: Text("Related")) {
|
||||
ForEach(player.currentVideo!.related) { video in
|
||||
PlayerQueueRow(item: PlayerQueueItem(video), fullScreen: $fullScreen)
|
||||
.contextMenu {
|
||||
Button("Play Next") {
|
||||
player.playNext(video)
|
||||
}
|
||||
Button("Play Last") {
|
||||
player.enqueueVideo(video)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func removeButton(_ item: PlayerQueueItem, history: Bool) -> some View {
|
||||
Button(role: .destructive) {
|
||||
if history {
|
||||
player.removeHistory(item)
|
||||
@@ -83,7 +103,7 @@ struct PlayerQueueView: View {
|
||||
}
|
||||
}
|
||||
|
||||
func removeAllButton(history: Bool) -> some View {
|
||||
private func removeAllButton(history: Bool) -> some View {
|
||||
Button(role: .destructive) {
|
||||
if history {
|
||||
player.removeHistoryItems()
|
||||
|
@@ -32,23 +32,29 @@ final class PlayerViewController: UIViewController {
|
||||
|
||||
#if os(tvOS)
|
||||
playerModel.avPlayerViewController = playerViewController
|
||||
playerViewController.customInfoViewControllers = [playerQueueInfoViewController]
|
||||
playerViewController.customInfoViewControllers = [
|
||||
infoViewController([.related], title: "Related"),
|
||||
infoViewController([.playingNext, .playedPreviously], title: "Playing Next")
|
||||
]
|
||||
#else
|
||||
embedViewController()
|
||||
#endif
|
||||
}
|
||||
|
||||
#if os(tvOS)
|
||||
var playerQueueInfoViewController: UIHostingController<AnyView> {
|
||||
func infoViewController(
|
||||
_ sections: [NowPlayingView.ViewSection],
|
||||
title: String
|
||||
) -> UIHostingController<AnyView> {
|
||||
let controller = UIHostingController(rootView:
|
||||
AnyView(
|
||||
NowPlayingView(inInfoViewController: true)
|
||||
NowPlayingView(sections: sections, inInfoViewController: true)
|
||||
.frame(maxHeight: 600)
|
||||
.environmentObject(playerModel)
|
||||
)
|
||||
)
|
||||
|
||||
controller.title = "Playing Next"
|
||||
controller.title = title
|
||||
|
||||
return controller
|
||||
}
|
||||
|
30
Shared/Player/RelatedView.swift
Normal file
30
Shared/Player/RelatedView.swift
Normal file
@@ -0,0 +1,30 @@
|
||||
import SwiftUI
|
||||
|
||||
struct RelatedView: View {
|
||||
@EnvironmentObject<PlayerModel> private var player
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
if !player.currentVideo.isNil, !player.currentVideo!.related.isEmpty {
|
||||
Section(header: Text("Related")) {
|
||||
ForEach(player.currentVideo!.related) { video in
|
||||
PlayerQueueRow(item: PlayerQueueItem(video), fullScreen: .constant(false))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#if os(macOS)
|
||||
.listStyle(.inset)
|
||||
#elseif os(iOS)
|
||||
.listStyle(.grouped)
|
||||
#else
|
||||
.listStyle(.plain)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
struct RelatedView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
RelatedView()
|
||||
}
|
||||
}
|
@@ -3,7 +3,7 @@ import SwiftUI
|
||||
|
||||
struct VideoDetails: View {
|
||||
enum Page {
|
||||
case details, queue
|
||||
case details, queue, related
|
||||
}
|
||||
|
||||
@Binding var sidebarQueue: Bool
|
||||
@@ -89,6 +89,14 @@ struct VideoDetails: View {
|
||||
case .queue:
|
||||
PlayerQueueView(fullScreen: $fullScreen)
|
||||
.edgesIgnoringSafeArea(.horizontal)
|
||||
|
||||
case .related:
|
||||
#if os(macOS)
|
||||
EmptyView()
|
||||
#else
|
||||
RelatedView()
|
||||
.edgesIgnoringSafeArea(.horizontal)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
.padding(.top, inNavigationView && fullScreen ? 10 : 0)
|
||||
@@ -109,7 +117,9 @@ struct VideoDetails: View {
|
||||
.onChange(of: sidebarQueue) { queue in
|
||||
#if !os(macOS)
|
||||
if queue {
|
||||
currentPage = .details
|
||||
if currentPage == .queue {
|
||||
currentPage = .details
|
||||
}
|
||||
} else {
|
||||
currentPage = .queue
|
||||
}
|
||||
@@ -216,6 +226,7 @@ struct VideoDetails: View {
|
||||
var pagePicker: some View {
|
||||
Picker("Page", selection: $currentPage) {
|
||||
Text("Details").tag(Page.details)
|
||||
Text("Related").tag(Page.related)
|
||||
Text("Queue").tag(Page.queue)
|
||||
}
|
||||
|
||||
|
@@ -62,8 +62,14 @@ struct VideoPlayerView: View {
|
||||
if player.currentItem.isNil {
|
||||
playerPlaceholder(geometry: geometry)
|
||||
} else {
|
||||
player.playerView
|
||||
.modifier(VideoPlayerSizeModifier(geometry: geometry))
|
||||
#if os(macOS)
|
||||
Player()
|
||||
.modifier(VideoPlayerSizeModifier(geometry: geometry))
|
||||
|
||||
#else
|
||||
player.playerView
|
||||
.modifier(VideoPlayerSizeModifier(geometry: geometry))
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#if os(iOS)
|
||||
@@ -107,6 +113,11 @@ struct VideoPlayerView: View {
|
||||
.frame(minWidth: 250)
|
||||
#endif
|
||||
}
|
||||
.onDisappear {
|
||||
if !player.playingInPictureInPicture {
|
||||
player.pause()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func playerPlaceholder(geometry: GeometryProxy) -> some View {
|
||||
|
Reference in New Issue
Block a user