From 79512d4cbf1df8ca25f260e9fea6f6f8e87979fd Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Fri, 2 Sep 2022 01:19:15 +0200 Subject: [PATCH] Extract playback stats view --- Shared/Player/Controls/ControlsOverlay.swift | 27 +------------- Shared/Player/Controls/OSD/NetworkState.swift | 2 +- .../Player/Controls/PlaybackStatsView.swift | 37 +++++++++++++++++++ Yattee.xcodeproj/project.pbxproj | 12 +++++- 4 files changed, 49 insertions(+), 29 deletions(-) create mode 100644 Shared/Player/Controls/PlaybackStatsView.swift diff --git a/Shared/Player/Controls/ControlsOverlay.swift b/Shared/Player/Controls/ControlsOverlay.swift index 7cbb3586..5b4facc2 100644 --- a/Shared/Player/Controls/ControlsOverlay.swift +++ b/Shared/Player/Controls/ControlsOverlay.swift @@ -2,7 +2,6 @@ import Defaults import SwiftUI struct ControlsOverlay: View { - @EnvironmentObject private var networkState @EnvironmentObject private var player @EnvironmentObject private var model @@ -73,7 +72,7 @@ struct ControlsOverlay: View { showMPVPlaybackStats { Section(header: controlsHeader("Statistics")) { - mpvPlaybackStats + PlaybackStatsView() } #if os(tvOS) .frame(width: 400) @@ -385,30 +384,6 @@ struct ControlsOverlay: View { } ) } - - var mpvPlaybackStats: some View { - VStack(alignment: .leading, spacing: 6) { - mpvPlaybackStatRow("Hardware decoder", player.mpvBackend.hwDecoder) - mpvPlaybackStatRow("Dropped frames", String(player.mpvBackend.frameDropCount)) - mpvPlaybackStatRow("Stream FPS", String(format: "%.2ffps", player.mpvBackend.outputFps)) - mpvPlaybackStatRow("Cached time", String(format: "%.2fs", player.mpvBackend.cacheDuration)) - } - .padding(.top, 2) - #if os(tvOS) - .font(.system(size: 20)) - #else - .font(.system(size: 11)) - #endif - } - - func mpvPlaybackStatRow(_ label: String, _ value: String) -> some View { - HStack { - Text(label) - .foregroundColor(.secondary) - Spacer() - Text(value) - } - } } struct ControlsOverlay_Previews: PreviewProvider { diff --git a/Shared/Player/Controls/OSD/NetworkState.swift b/Shared/Player/Controls/OSD/NetworkState.swift index 24c400e8..56f8bc27 100644 --- a/Shared/Player/Controls/OSD/NetworkState.swift +++ b/Shared/Player/Controls/OSD/NetworkState.swift @@ -1,7 +1,7 @@ import SwiftUI struct NetworkState: View { - @EnvironmentObject private var model + @ObservedObject private var model = NetworkStateModel.shared var body: some View { Buffering(state: model.fullStateText) diff --git a/Shared/Player/Controls/PlaybackStatsView.swift b/Shared/Player/Controls/PlaybackStatsView.swift new file mode 100644 index 00000000..37aeb001 --- /dev/null +++ b/Shared/Player/Controls/PlaybackStatsView.swift @@ -0,0 +1,37 @@ +import SwiftUI + +struct PlaybackStatsView: View { + @ObservedObject private var networkState = NetworkStateModel.shared + + private var player: PlayerModel { .shared } + + var body: some View { + VStack(alignment: .leading, spacing: 6) { + mpvPlaybackStatRow("Hardware decoder", player.mpvBackend.hwDecoder) + mpvPlaybackStatRow("Dropped frames", String(player.mpvBackend.frameDropCount)) + mpvPlaybackStatRow("Stream FPS", String(format: "%.2ffps", player.mpvBackend.outputFps)) + mpvPlaybackStatRow("Cached time", String(format: "%.2fs", player.mpvBackend.cacheDuration)) + } + .padding(.top, 2) + #if os(tvOS) + .font(.system(size: 20)) + #else + .font(.system(size: 11)) + #endif + } + + func mpvPlaybackStatRow(_ label: String, _ value: String) -> some View { + HStack { + Text(label) + .foregroundColor(.secondary) + Spacer() + Text(value) + } + } +} + +struct PlaybackStatsView_Previews: PreviewProvider { + static var previews: some View { + PlaybackStatsView() + } +} diff --git a/Yattee.xcodeproj/project.pbxproj b/Yattee.xcodeproj/project.pbxproj index d3f38e1d..3cebf029 100644 --- a/Yattee.xcodeproj/project.pbxproj +++ b/Yattee.xcodeproj/project.pbxproj @@ -745,6 +745,9 @@ 37D526DE2720AC4400ED2F5E /* VideosAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37D526DD2720AC4400ED2F5E /* VideosAPI.swift */; }; 37D526DF2720AC4400ED2F5E /* VideosAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37D526DD2720AC4400ED2F5E /* VideosAPI.swift */; }; 37D526E02720AC4400ED2F5E /* VideosAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37D526DD2720AC4400ED2F5E /* VideosAPI.swift */; }; + 37D6025928C17375009E8D98 /* PlaybackStatsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37D6025828C17375009E8D98 /* PlaybackStatsView.swift */; }; + 37D6025A28C17375009E8D98 /* PlaybackStatsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37D6025828C17375009E8D98 /* PlaybackStatsView.swift */; }; + 37D6025B28C17375009E8D98 /* PlaybackStatsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37D6025828C17375009E8D98 /* PlaybackStatsView.swift */; }; 37DD87C7271C9CFE0027CBF9 /* PlayerStreams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37DD87C6271C9CFE0027CBF9 /* PlayerStreams.swift */; }; 37DD87C8271C9CFE0027CBF9 /* PlayerStreams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37DD87C6271C9CFE0027CBF9 /* PlayerStreams.swift */; }; 37DD87C9271C9CFE0027CBF9 /* PlayerStreams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37DD87C6271C9CFE0027CBF9 /* PlayerStreams.swift */; }; @@ -1260,6 +1263,7 @@ 37D4B19626717E1500C925CA /* Video.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Video.swift; sourceTree = ""; }; 37D4B1AE26729DEB00C925CA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 37D526DD2720AC4400ED2F5E /* VideosAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideosAPI.swift; sourceTree = ""; }; + 37D6025828C17375009E8D98 /* PlaybackStatsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybackStatsView.swift; sourceTree = ""; }; 37D9169A27388A81002B1BAA /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 37DD87C6271C9CFE0027CBF9 /* PlayerStreams.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerStreams.swift; sourceTree = ""; }; 37DD9DA22785BBC900539416 /* NoCommentsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoCommentsView.swift; sourceTree = ""; }; @@ -1552,12 +1556,13 @@ 3756C2A428610F6D00E4B059 /* OSD */, 37A5DBC7285E371400CA4DD1 /* ControlBackgroundModifier.swift */, 37F13B61285E43C000B137E4 /* ControlsOverlay.swift */, + 37D6025828C17375009E8D98 /* PlaybackStatsView.swift */, 37030FFE27B04DCC00ECDDAA /* PlayerControls.swift */, + 3744A95F28B99ADD005DE0A7 /* PlayerControlsLayout.swift */, + 370015A828BBAE7F000149FD /* ProgressBar.swift */, 37E8B0EB27B326C00024006F /* TimelineView.swift */, 37648B68286CF5F1003D330B /* TVControls.swift */, 37E80F3B287B107F00561799 /* VideoDetailsOverlay.swift */, - 3744A95F28B99ADD005DE0A7 /* PlayerControlsLayout.swift */, - 370015A828BBAE7F000149FD /* ProgressBar.swift */, ); path = Controls; sourceTree = ""; @@ -2960,6 +2965,7 @@ 37B81AFC26D2C9C900675966 /* VideoDetailsPaddingModifier.swift in Sources */, 37C7A1D5267BFD9D0010EAD6 /* SponsorBlockSegment.swift in Sources */, 37BA794F26DC3E0E002A0235 /* Int+Format.swift in Sources */, + 37D6025928C17375009E8D98 /* PlaybackStatsView.swift in Sources */, 37F49BA326CAA59B00304AC0 /* Playlist+Fixtures.swift in Sources */, 374C053B2724614F009BDDBE /* PlayerTVMenu.swift in Sources */, 37A9965A26D6F8CA006E3224 /* HorizontalCells.swift in Sources */, @@ -3082,6 +3088,7 @@ 37FB285F272225E800A57617 /* ContentItemView.swift in Sources */, 37FD43DC270470B70073EE42 /* InstancesSettings.swift in Sources */, 3756C2A72861131100E4B059 /* NetworkState.swift in Sources */, + 37D6025A28C17375009E8D98 /* PlaybackStatsView.swift in Sources */, 3729037F2739E47400EA99F6 /* MenuCommands.swift in Sources */, 37C0698327260B2100F7F6CB /* ThumbnailsModel.swift in Sources */, 374AB3DC28BCAF7E00DF56FB /* SeekType.swift in Sources */, @@ -3373,6 +3380,7 @@ 37A5DBCA285E371400CA4DD1 /* ControlBackgroundModifier.swift in Sources */, 37E80F46287B7AEC00561799 /* PlayerQueueView.swift in Sources */, 37C0698427260B2100F7F6CB /* ThumbnailsModel.swift in Sources */, + 37D6025B28C17375009E8D98 /* PlaybackStatsView.swift in Sources */, 37666BAA27023AF000F869E5 /* AccountSelectionView.swift in Sources */, 3765788B2685471400D4EA09 /* Playlist.swift in Sources */, 376A33E22720CAD6000C1D6B /* VideosApp.swift in Sources */,