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:
Timothy Flynn 2024-03-30 09:34:23 -04:00 committed by Andreas Kling
parent c7c7ed780b
commit 9fc8c37414
Notes: sideshowbarker 2024-07-17 00:57:24 +09:00
2 changed files with 19 additions and 2 deletions

View file

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

View file

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