mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 17:18:11 +00:00
LibWeb: Implement seeking for audio tracks
This commit is contained in:
parent
0c4b28faf3
commit
ff1606ffaf
4 changed files with 20 additions and 0 deletions
|
@ -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);
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ private:
|
|||
|
||||
virtual void on_playing() override;
|
||||
virtual void on_paused() override;
|
||||
virtual void on_seek(double, MediaSeekMode) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue