mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
LibWebView: Handle mutliple audio tracks when audio play state changes
For example, if a page has multiple audio elements all actively playing audio, we don't want to broadcast a play state change when only one of them stop playing.
This commit is contained in:
parent
c7c7ed780b
commit
9fc8c37414
Notes:
sideshowbarker
2024-07-17 00:57:24 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/9fc8c37414 Pull-request: https://github.com/SerenityOS/serenity/pull/23773
2 changed files with 19 additions and 2 deletions
|
@ -317,9 +317,25 @@ void ViewImplementation::toggle_media_controls_state()
|
|||
|
||||
void ViewImplementation::did_change_audio_play_state(Badge<WebContentClient>, Web::HTML::AudioPlayState play_state)
|
||||
{
|
||||
m_audio_play_state = play_state;
|
||||
bool state_changed = false;
|
||||
|
||||
if (on_audio_play_state_changed)
|
||||
switch (play_state) {
|
||||
case Web::HTML::AudioPlayState::Paused:
|
||||
if (--m_number_of_elements_playing_audio == 0) {
|
||||
m_audio_play_state = play_state;
|
||||
state_changed = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case Web::HTML::AudioPlayState::Playing:
|
||||
if (m_number_of_elements_playing_audio++ == 0) {
|
||||
m_audio_play_state = play_state;
|
||||
state_changed = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (state_changed && on_audio_play_state_changed)
|
||||
on_audio_play_state_changed(m_audio_play_state);
|
||||
}
|
||||
|
||||
|
|
|
@ -260,6 +260,7 @@ protected:
|
|||
RefPtr<Core::Promise<LexicalPath>> m_pending_screenshot;
|
||||
|
||||
Web::HTML::AudioPlayState m_audio_play_state { Web::HTML::AudioPlayState::Paused };
|
||||
size_t m_number_of_elements_playing_audio { 0 };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue