mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-15 02:40:38 +00:00
SoundPlayer: Sync startup loop and show playlist settings in GUI
This fix syncs up the AudioPlayer's internal state for showing playlist information with the AudioPlayer's GUI. Before, if the AudioPlayer was opened with a playlist file (.m3u or .m3u8) it would automatically show the playlist information in the GUI and set the loop mode to playlist, but the menu options would be unchecked. In order to hide the playlist information, the menu option would then have to be toggled twice -- once on and again off.
This commit is contained in:
parent
277ac48649
commit
c8eab80b3d
Notes:
sideshowbarker
2024-07-17 22:17:36 +09:00
Author: https://github.com/maxtrussell Commit: https://github.com/SerenityOS/serenity/commit/c8eab80b3da Pull-request: https://github.com/SerenityOS/serenity/pull/11327 Reviewed-by: https://github.com/bgianfo Reviewed-by: https://github.com/kleinesfilmroellchen
3 changed files with 17 additions and 5 deletions
|
@ -48,7 +48,7 @@ void Player::play_file_path(String const& path)
|
|||
return;
|
||||
}
|
||||
|
||||
if (path.ends_with(".m3u", AK::CaseSensitivity::CaseInsensitive) || path.ends_with(".m3u8", AK::CaseSensitivity::CaseInsensitive)) {
|
||||
if (is_playlist(path)) {
|
||||
playlist_loaded(path, m_playlist.load(path));
|
||||
return;
|
||||
}
|
||||
|
@ -69,6 +69,12 @@ void Player::play_file_path(String const& path)
|
|||
play();
|
||||
}
|
||||
|
||||
bool Player::is_playlist(String const& path)
|
||||
{
|
||||
return (path.ends_with(".m3u", AK::CaseSensitivity::CaseInsensitive)
|
||||
|| path.ends_with(".m3u8", AK::CaseSensitivity::CaseInsensitive));
|
||||
}
|
||||
|
||||
void Player::set_play_state(PlayState state)
|
||||
{
|
||||
if (m_play_state != state) {
|
||||
|
|
|
@ -33,6 +33,7 @@ public:
|
|||
virtual ~Player() { }
|
||||
|
||||
void play_file_path(String const& path);
|
||||
bool is_playlist(String const& path);
|
||||
|
||||
Playlist& playlist() { return m_playlist; }
|
||||
String const& loaded_filename() const { return m_loaded_filename; }
|
||||
|
|
|
@ -43,6 +43,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
if (arguments.argc > 1) {
|
||||
StringView path = arguments.strings[1];
|
||||
player->play_file_path(path);
|
||||
if (player->is_playlist(path))
|
||||
player->set_loop_mode(Player::LoopMode::Playlist);
|
||||
}
|
||||
|
||||
auto file_menu = TRY(window->try_add_menu("&File"));
|
||||
|
@ -61,10 +63,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto playback_menu = TRY(window->try_add_menu("&Playback"));
|
||||
GUI::ActionGroup loop_actions;
|
||||
loop_actions.set_exclusive(true);
|
||||
auto loop_none = TRY(GUI::Action::try_create("&No Loop", [&](auto&) {
|
||||
auto loop_none = GUI::Action::create_checkable("&No Loop", { Mod_Ctrl, Key_N }, [&](auto&) {
|
||||
player->set_loop_mode(Player::LoopMode::None);
|
||||
}));
|
||||
loop_none->set_checked(true);
|
||||
});
|
||||
loop_actions.add_action(loop_none);
|
||||
TRY(playback_menu->try_add_action(loop_none));
|
||||
|
||||
|
@ -90,8 +91,12 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto playlist_toggle = GUI::Action::create_checkable("&Show Playlist", [&](auto& action) {
|
||||
static_cast<SoundPlayerWidgetAdvancedView*>(player)->set_playlist_visible(action.is_checked());
|
||||
});
|
||||
if (player->loop_mode() == Player::LoopMode::Playlist)
|
||||
if (player->loop_mode() == Player::LoopMode::Playlist) {
|
||||
playlist_toggle->set_checked(true);
|
||||
loop_playlist->set_checked(true);
|
||||
} else {
|
||||
loop_none->set_checked(true);
|
||||
}
|
||||
TRY(playback_menu->try_add_action(playlist_toggle));
|
||||
|
||||
auto shuffle_mode = GUI::Action::create_checkable("S&huffle Playlist", [&](auto& action) {
|
||||
|
|
Loading…
Reference in a new issue