mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 19:45:12 +00:00
LibWeb: Play audio tracks alongside video tracks with the video element
The underlying media element class already parses out the audio tracks, regardless of the media type. Let's play them with videos!
This commit is contained in:
parent
4df2de2f20
commit
509eaca73d
Notes:
github-actions[bot]
2025-03-13 18:34:45 +00:00
Author: https://github.com/Lubrsi Commit: https://github.com/LadybirdBrowser/ladybird/commit/509eaca73dd Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3892 Reviewed-by: https://github.com/ADKaster
5 changed files with 27 additions and 6 deletions
|
@ -60,12 +60,12 @@ void AudioTrack::initialize(JS::Realm& realm)
|
|||
m_id = String::number(id);
|
||||
}
|
||||
|
||||
void AudioTrack::play(Badge<HTMLAudioElement>)
|
||||
void AudioTrack::play()
|
||||
{
|
||||
m_audio_plugin->resume_playback();
|
||||
}
|
||||
|
||||
void AudioTrack::pause(Badge<HTMLAudioElement>)
|
||||
void AudioTrack::pause()
|
||||
{
|
||||
m_audio_plugin->pause_playback();
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@ public:
|
|||
|
||||
void set_audio_track_list(Badge<AudioTrackList>, GC::Ptr<AudioTrackList> audio_track_list) { m_audio_track_list = audio_track_list; }
|
||||
|
||||
void play(Badge<HTMLAudioElement>);
|
||||
void pause(Badge<HTMLAudioElement>);
|
||||
void play();
|
||||
void pause();
|
||||
|
||||
AK::Duration duration();
|
||||
void seek(double, MediaSeekMode);
|
||||
|
|
|
@ -55,14 +55,14 @@ Layout::AudioBox const* HTMLAudioElement::layout_node() const
|
|||
void HTMLAudioElement::on_playing()
|
||||
{
|
||||
audio_tracks()->for_each_enabled_track([](auto& audio_track) {
|
||||
audio_track.play({});
|
||||
audio_track.play();
|
||||
});
|
||||
}
|
||||
|
||||
void HTMLAudioElement::on_paused()
|
||||
{
|
||||
audio_tracks()->for_each_enabled_track([](auto& audio_track) {
|
||||
audio_track.pause({});
|
||||
audio_track.pause();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <LibWeb/Fetch/Infrastructure/FetchController.h>
|
||||
#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
|
||||
#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>
|
||||
#include <LibWeb/HTML/AudioTrackList.h>
|
||||
#include <LibWeb/HTML/HTMLVideoElement.h>
|
||||
#include <LibWeb/HTML/VideoTrack.h>
|
||||
#include <LibWeb/HTML/VideoTrackList.h>
|
||||
|
@ -130,18 +131,37 @@ void HTMLVideoElement::on_playing()
|
|||
{
|
||||
if (m_video_track)
|
||||
m_video_track->play_video({});
|
||||
|
||||
audio_tracks()->for_each_enabled_track([](auto& audio_track) {
|
||||
audio_track.play();
|
||||
});
|
||||
}
|
||||
|
||||
void HTMLVideoElement::on_paused()
|
||||
{
|
||||
if (m_video_track)
|
||||
m_video_track->pause_video({});
|
||||
|
||||
audio_tracks()->for_each_enabled_track([](auto& audio_track) {
|
||||
audio_track.pause();
|
||||
});
|
||||
}
|
||||
|
||||
void HTMLVideoElement::on_seek(double position, MediaSeekMode seek_mode)
|
||||
{
|
||||
if (m_video_track)
|
||||
m_video_track->seek(AK::Duration::from_milliseconds(position * 1000.0), seek_mode);
|
||||
|
||||
audio_tracks()->for_each_enabled_track([&](auto& audio_track) {
|
||||
audio_track.seek(position, seek_mode);
|
||||
});
|
||||
}
|
||||
|
||||
void HTMLVideoElement::on_volume_change()
|
||||
{
|
||||
audio_tracks()->for_each_enabled_track([&](auto& audio_track) {
|
||||
audio_track.update_volume();
|
||||
});
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/media.html#attr-video-poster
|
||||
|
|
|
@ -66,6 +66,7 @@ private:
|
|||
virtual void on_playing() override;
|
||||
virtual void on_paused() override;
|
||||
virtual void on_seek(double, MediaSeekMode) override;
|
||||
virtual void on_volume_change() override;
|
||||
|
||||
WebIDL::ExceptionOr<void> determine_element_poster_frame(Optional<String> const& poster);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue