SoundPlayer: Display title and artist in the window title if available

This commit is contained in:
kleines Filmröllchen 2023-03-07 17:32:05 +01:00 committed by Tim Flynn
parent 0563048949
commit 68447d8f39
Notes: sideshowbarker 2024-07-17 03:59:29 +09:00
2 changed files with 13 additions and 1 deletions

View file

@ -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; }

View file

@ -9,6 +9,7 @@
#include "BarsVisualizationWidget.h"
#include "M3UParser.h"
#include "PlaybackManager.h"
#include <AK/DeprecatedString.h>
#include <AK/LexicalPath.h>
#include <AK/SIMD.h>
#include <LibGUI/Action.h>
@ -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)