1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-15 14:50:32 +05:30
yattee/Shared/Player/Video Details/InspectorView.swift

102 lines
4.1 KiB
Swift
Raw Normal View History

2022-11-13 23:22:15 +05:30
import SwiftUI
struct InspectorView: View {
var video: Video?
@ObservedObject private var player = PlayerModel.shared
2022-11-13 23:22:15 +05:30
var body: some View {
Section(header: header) {
2022-11-14 02:22:29 +05:30
VStack(alignment: .leading, spacing: 12) {
2022-11-13 23:22:15 +05:30
if let video {
2022-11-14 02:22:29 +05:30
VStack(spacing: 4) {
2022-11-13 23:22:15 +05:30
if player.activeBackend == .mpv, player.mpvBackend.videoFormat != "unknown" {
2022-11-14 02:22:29 +05:30
videoDetailGroupHeading("Video", image: "film")
2022-11-13 23:22:15 +05:30
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-14 02:22:29 +05:30
VStack(spacing: 4) {
videoDetailGroupHeading("Audio", image: "music.note")
2022-11-13 23:22:15 +05:30
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-14 02:22:29 +05:30
VStack(spacing: 4) {
if video.localStream != nil || video.localStreamFileExtension != nil {
videoDetailGroupHeading("File", image: "doc")
}
2022-11-13 23:22:15 +05:30
2022-11-14 02:22:29 +05:30
if let fileExtension = video.localStreamFileExtension {
videoDetailRow("File Extension", value: fileExtension)
}
2022-11-13 23:22:15 +05:30
2022-11-14 02:22:29 +05:30
if let url = video.localStream?.localURL, video.localStreamIsRemoteURL {
videoDetailRow("URL", value: url.absoluteString)
}
2022-11-13 23:22:15 +05:30
}
2022-11-14 02:22:29 +05:30
} else {
NoCommentsView(text: "Not playing", systemImage: "stop.circle.fill")
2022-11-13 23:22:15 +05:30
}
}
}
}
var header: some View {
2023-04-22 17:26:25 +05:30
Text("Inspector".localized())
.font(.caption)
.foregroundColor(.secondary)
.frame(maxWidth: .infinity, alignment: .leading)
2022-11-13 23:22:15 +05:30
}
2022-11-14 02:22:29 +05:30
@ViewBuilder func videoDetailGroupHeading(_ heading: String, image systemName: String? = nil) -> some View {
HStack {
if let systemName {
Image(systemName: systemName)
}
2022-11-19 04:36:13 +05:30
Text(heading.localized().uppercased())
2022-11-14 02:22:29 +05:30
.font(.footnote)
}
.foregroundColor(.secondary)
2022-11-13 23:22:15 +05:30
}
@ViewBuilder func videoDetailRow(_ detail: String, value: String) -> some View {
HStack {
2022-11-19 04:36:13 +05:30
Text(detail.localized())
2022-11-13 23:22:15 +05:30
.foregroundColor(.secondary)
Spacer()
let value = Text(value).lineLimit(1)
2022-11-13 23:22:15 +05:30
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-14 02:22:29 +05:30
.injectFixtureEnvironmentObjects()
2022-11-13 23:22:15 +05:30
}
}