From 68447d8f3921096aa6621983f4d9de512d94c4bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Tue, 7 Mar 2023 17:32:05 +0100 Subject: [PATCH] SoundPlayer: Display title and artist in the window title if available --- Userland/Applications/SoundPlayer/Player.h | 1 + .../SoundPlayer/SoundPlayerWidgetAdvancedView.cpp | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Userland/Applications/SoundPlayer/Player.h b/Userland/Applications/SoundPlayer/Player.h index c6876459e7..f0b2765533 100644 --- a/Userland/Applications/SoundPlayer/Player.h +++ b/Userland/Applications/SoundPlayer/Player.h @@ -39,6 +39,7 @@ public: bool is_playlist(DeprecatedString const& path); Playlist& playlist() { return m_playlist; } + PlaybackManager const& playback_manager() const { return m_playback_manager; } DeprecatedString const& loaded_filename() const { return m_loaded_filename; } PlayState play_state() const { return m_play_state; } diff --git a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp index c3fe2f1f19..9fe0fc8aae 100644 --- a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp +++ b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp @@ -9,6 +9,7 @@ #include "BarsVisualizationWidget.h" #include "M3UParser.h" #include "PlaybackManager.h" +#include #include #include #include @@ -215,7 +216,17 @@ void SoundPlayerWidgetAdvancedView::time_elapsed(int seconds) void SoundPlayerWidgetAdvancedView::file_name_changed(StringView name) { m_visualization->start_new_file(name); - m_window.set_title(DeprecatedString::formatted("{} - Sound Player", name)); + DeprecatedString title = name; + if (playback_manager().loader()) { + auto const& metadata = playback_manager().loader()->metadata(); + if (auto artists_or_error = metadata.all_artists(" / "_short_string); + !artists_or_error.is_error() && artists_or_error.value().has_value() && metadata.title.has_value()) { + title = DeprecatedString::formatted("{} – {}", metadata.title.value(), artists_or_error.release_value().release_value()); + } else if (metadata.title.has_value()) { + title = metadata.title.value().to_deprecated_string(); + } + } + m_window.set_title(DeprecatedString::formatted("{} — Sound Player", title)); } void SoundPlayerWidgetAdvancedView::total_samples_changed(int total_samples)