mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 17:06:31 +00:00
LibWeb: Implement seeking for audio tracks
This commit is contained in:
parent
0c4b28faf3
commit
ff1606ffaf
|
@ -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…
Reference in a new issue