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

102 lines
4.1 KiB
Swift
Raw Normal View History

2022-11-13 17:52:15 +00:00
import SwiftUI
struct InspectorView: View {
var video: Video?
@ObservedObject private var player = PlayerModel.shared
2022-11-13 17:52:15 +00:00
var body: some View {
Section(header: header) {
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
}
}
}
}
var header: some View {
2023-04-22 11:56:25 +00:00
Text("Inspector".localized())
.font(.caption)
.foregroundColor(.secondary)
.frame(maxWidth: .infinity, alignment: .leading)
2022-11-13 17:52:15 +00:00
}
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)
}
2022-11-18 23:06:13 +00:00
Text(heading.localized().uppercased())
2022-11-13 20:52:29 +00:00
.font(.footnote)
}
.foregroundColor(.secondary)
2022-11-13 17:52:15 +00:00
}
@ViewBuilder func videoDetailRow(_ detail: String, value: String) -> some View {
HStack {
2022-11-18 23:06:13 +00:00
Text(detail.localized())
2022-11-13 17:52:15 +00:00
.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
}
}