yattee/Shared/Player/Video Details/InspectorView.swift

98 lines
3.9 KiB
Swift
Raw Normal View History

2022-11-13 17:52:15 +00:00
import SwiftUI
struct InspectorView: View {
var video: Video?
@EnvironmentObject<PlayerModel> private var player
var body: some View {
ScrollView {
2022-11-13 20:52:29 +00:00
VStack(alignment: .leading, spacing: 12) {
2022-11-13 17:52:15 +00:00
if let video {
2022-11-13 20:52:29 +00:00
VStack(spacing: 4) {
2022-11-13 17:52:15 +00:00
if player.activeBackend == .mpv, player.mpvBackend.videoFormat != "unknown" {
2022-11-13 20:52:29 +00:00
videoDetailGroupHeading("Video", image: "film")
2022-11-13 17:52:15 +00:00
videoDetailRow("Format", value: player.mpvBackend.videoFormat)
videoDetailRow("Codec", value: player.mpvBackend.videoCodec)
videoDetailRow("Hardware Decoder", value: player.mpvBackend.hwDecoder)
videoDetailRow("Driver", value: player.mpvBackend.currentVo)
videoDetailRow("Size", value: player.formattedSize)
videoDetailRow("FPS", value: player.mpvBackend.formattedOutputFps)
} else if player.activeBackend == .appleAVPlayer, let width = player.backend.videoWidth, width > 0 {
videoDetailGroupHeading("Video")
videoDetailRow("Size", value: player.formattedSize)
}
}
if player.activeBackend == .mpv, player.mpvBackend.audioFormat != "unknown" {
2022-11-13 20:52:29 +00:00
VStack(spacing: 4) {
videoDetailGroupHeading("Audio", image: "music.note")
2022-11-13 17:52:15 +00:00
videoDetailRow("Format", value: player.mpvBackend.audioFormat)
videoDetailRow("Codec", value: player.mpvBackend.audioCodec)
videoDetailRow("Driver", value: player.mpvBackend.currentAo)
videoDetailRow("Channels", value: player.mpvBackend.audioChannels)
videoDetailRow("Sample Rate", value: player.mpvBackend.audioSampleRate)
}
}
2022-11-13 20:52:29 +00:00
VStack(spacing: 4) {
if video.localStream != nil || video.localStreamFileExtension != nil {
videoDetailGroupHeading("File", image: "doc")
}
2022-11-13 17:52:15 +00:00
2022-11-13 20:52:29 +00:00
if let fileExtension = video.localStreamFileExtension {
videoDetailRow("File Extension", value: fileExtension)
}
2022-11-13 17:52:15 +00:00
2022-11-13 20:52:29 +00:00
if let url = video.localStream?.localURL, video.localStreamIsRemoteURL {
videoDetailRow("URL", value: url.absoluteString)
}
2022-11-13 17:52:15 +00:00
}
2022-11-13 20:52:29 +00:00
} else {
NoCommentsView(text: "Not playing", systemImage: "stop.circle.fill")
2022-11-13 17:52:15 +00:00
}
}
2022-11-13 20:52:29 +00:00
.padding(.top, 10)
.padding(.bottom, 50)
2022-11-13 17:52:15 +00:00
}
.padding(.horizontal)
}
2022-11-13 20:52:29 +00:00
@ViewBuilder func videoDetailGroupHeading(_ heading: String, image systemName: String? = nil) -> some View {
HStack {
if let systemName {
Image(systemName: systemName)
}
Text(heading.uppercased())
.font(.footnote)
}
.foregroundColor(.secondary)
2022-11-13 17:52:15 +00:00
}
@ViewBuilder func videoDetailRow(_ detail: String, value: String) -> some View {
HStack {
Text(detail)
.foregroundColor(.secondary)
Spacer()
let value = Text(value).lineLimit(1)
2022-11-13 17:52:15 +00:00
if #available(iOS 15.0, macOS 12.0, *) {
value
#if !os(tvOS)
.textSelection(.enabled)
#endif
} else {
value
}
}
.font(.caption)
}
}
struct InspectorView_Previews: PreviewProvider {
static var previews: some View {
InspectorView(video: .fixture)
2022-11-13 20:52:29 +00:00
.injectFixtureEnvironmentObjects()
2022-11-13 17:52:15 +00:00
}
}