Repository: servo/servo
File: components/script/dom/html/htmlmediaelement.rs (Rust)

Code before:
        self.seeking.get()
    }

    /// <https://html.spec.whatwg.org/multipage/#dom-media-ended>
    fn Ended(&self) -> bool {
        self.ended_playback() && self.direction_of_playback() == PlaybackDirection::Forwards
    }

    /// <https://html.spec.whatwg.org/multipage/#dom-media-fastseek>
    fn FastSeek(&self, time: Finite<f64>) {
        self.seek(*time, /* approximate_for_speed */ true);
    }

    /// <https://html.spec.whatwg.org/multipage/#dom-media-played>
    fn Played(&self, can_gc: CanGc) -> DomRoot<TimeRanges> {
        TimeRanges::new(
            self.global().as_window(),
            self.played.borrow().clone(),
            can_gc,
        )
    }

    /// <https://html.spec.whatwg.org/multipage/#dom-media-seekable>
    fn Seekable(&self, can_gc: CanGc) -> DomRoot<TimeRanges> {
        TimeRanges::new(self.global().as_window(), self.seekable(), can_gc)
    }

    /// <https://html.spec.whatwg.org/multipage/#dom-media-buffered>
    fn Buffered(&self, can_gc: CanGc) -> DomRoot<TimeRanges> {
        let mut buffered = TimeRangesContainer::default();
        if let Some(ref player) = *self.player.borrow() {
            if let Ok(ranges) = player.lock().unwrap().buffered() {
                for range in ranges {
                    let _ = buffered.add(range.start, range.end);
                }
            }
        }
        TimeRanges::new(self.global().as_window(), buffered, can_gc)
    }

    /// <https://html.spec.whatwg.org/multipage/#dom-media-audiotracks>
    fn AudioTracks(&self, can_gc: CanGc) -> DomRoot<AudioTrackList> {
        let window = self.owner_window();
        self.audio_tracks_list
            .or_init(|| AudioTrackList::new(&window, &[], Some(self), can_gc))
    }

    /// <https://html.spec.whatwg.org/multipage/#dom-media-videotracks>
    fn VideoTracks(&self, can_gc: CanGc) -> DomRoot<VideoTrackList> {
        let window = self.owner_window();
        self.video_tracks_list

Review comment (suggestion):
Chromium: [HTMLMediaElement::currentTime](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/html/media/html_media_element.cc;l=2725)
FIrefox: [HTMLMediaElement::currentTime](https://github.com/mozilla-firefox/firefox/blob/7690c1665f50744641e0bd97fc22c3dc26f0b092/dom/media/mediaelement/HTMLMediaElement.cpp#L3365) + [HTMLMediaElement::SetCurrentTime](https://github.com/mozilla-firefox/firefox/blob/7690c1665f50744641e0bd97fc22c3dc26f0b092/dom/media/mediaelement/HTMLMediaElement.cpp#L3407) set the `official` playback position to clamped position in [HTMLMediaElement::Seek](https://github.com/mozilla-firefox/firefox/blob/7690c1665f50744641e0bd97fc22c3dc26f0b092/dom/media/mediaelement/HTMLMediaElement.cpp#L3551)

Code after:

        if *value != self.playbackRate.get() {
            self.playbackRate.set(*value);
            self.queue_media_element_task_to_fire_event(atom!("ratechange"));
            if self.is_potentially_playing() {
                if let Some(ref player) = *self.player.borrow() {
                    if let Err(e) = player.lock().unwrap().set_rate(*value) {
                        warn!("Could not set the playback rate {:?}", e);
                    }
                }
            }
        }

        Ok(())
    }

    /// <https://html.spec.whatwg.org/multipage/#dom-media-duration>
    fn Duration(&self) -> f64 {
        self.duration.get()
    }

    /// <https://html.spec.whatwg.org/multipage/#dom-media-currenttime>
    fn CurrentTime(&self) -> Finite<f64> {
        Finite::wrap(if self.default_playback_start_position.get() != 0. {
            self.default_playback_start_position.get()
        } else if self.seeking.get() {
            // Following the specification, any time the user agent provides a stable state, the
            // official playback position must be set to the current playback position, and
            // the `await a stable state` for `seek` (step 13) will be reached on receiving the
            // `seek completion` signal from media engine, so the current playback position should
            // be returned until the official playback position will be updated in `seek_end`.
            // <https://html.spec.whatwg.org/multipage/#playing-the-media-resource:official-playback-position-2>
            // <https://html.spec.whatwg.org/multipage/#dom-media-seek>
            // Note that the other browsers do the similar (by checking `seeking` value or make no
            // difference between `current` and `official` playback positions).
            self.current_playback_position.get()
        } else {
            self.official_playback_position.get()
        })
    }

    /// <https://html.spec.whatwg.org/multipage/#dom-media-currenttime>
    fn SetCurrentTime(&self, time: Finite<f64>) {
        if self.ready_state.get() == ReadyState::HaveNothing {
            self.default_playback_start_position.set(*time);
        } else {
            self.official_playback_position.set(*time);
            self.seek(*time, /* approximate_for_speed */ false);
        }
    }