LibWeb: Implement seeking for audio tracks

This commit is contained in:
Timothy Flynn 2023-06-14 10:12:46 -04:00 committed by Andreas Kling
parent 0c4b28faf3
commit ff1606ffaf
4 changed files with 20 additions and 0 deletions

View file

@ -89,6 +89,17 @@ Duration AudioTrack::duration() const
return Duration::from_milliseconds(static_cast<i64>(duration * 1000.0));
}
void AudioTrack::seek(double position, MediaSeekMode seek_mode)
{
// FIXME: Implement seeking mode.
(void)seek_mode;
auto duration = static_cast<double>(this->duration().to_milliseconds()) / 1000.0;
position = position / duration * static_cast<double>(m_loader->total_samples());
m_loader->seek(position).release_value_but_fixme_should_propagate_errors();
}
void AudioTrack::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);

View file

@ -26,6 +26,7 @@ public:
Duration position() const;
Duration duration() const;
void seek(double, MediaSeekMode);
String const& id() const { return m_id; }
String const& kind() const { return m_kind; }

View file

@ -56,4 +56,11 @@ void HTMLAudioElement::on_paused()
});
}
void HTMLAudioElement::on_seek(double position, MediaSeekMode seek_mode)
{
audio_tracks()->for_each_enabled_track([&](auto& audio_track) {
audio_track.seek(position, seek_mode);
});
}
}

View file

@ -28,6 +28,7 @@ private:
virtual void on_playing() override;
virtual void on_paused() override;
virtual void on_seek(double, MediaSeekMode) override;
};
}