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

Code before:
            }
        }
        let time = if in_seekable_range {
            time
        } else {
            nearest_seekable_position
        };

        // Step 9. If the approximate-for-speed flag is set, adjust the new playback position to a
        // value that will allow for playback to resume promptly. If new playback position before
        // this step is before current playback position, then the adjusted new playback position
        // must also be before the current playback position. Similarly, if the new playback
        // position before this step is after current playback position, then the adjusted new
        // playback position must also be after the current playback position.
        // TODO: Note that servo-media with gstreamer does not support inaccurate seeking for now.

        // Step 10. Queue a media element task given the media element to fire an event named
        // seeking at the element.
        self.queue_media_element_task_to_fire_event(atom!("seeking"));

        // Step 11. Set the current playback position to the new playback position.
        self.current_playback_position.set(time);

        if let Some(ref player) = *self.player.borrow() {
            if let Err(err) = player.lock().unwrap().seek(time) {
                error!("Seek error {:?}", err);
            }
        }

        self.current_seek_position.set(time);

        // Step 12. Wait until the user agent has established whether or not the media data for the
        // new playback position is available, and, if it is, until it has decoded enough data to
        // play back that position.
        // The rest of the steps are handled when the media engine signals a ready state change or
        // otherwise satisfies seek completion and signals a position change.
    }

    /// <https://html.spec.whatwg.org/multipage/#dom-media-seek>
    fn seek_end(&self) {
        // Any time the user agent provides a stable state, the official playback position must be
        // set to the current playback position.
        self.official_playback_position
            .set(self.current_playback_position.get());

        // Step 14. Set the seeking IDL attribute to false.
        self.seeking.set(false);

        self.current_seek_position.set(f64::NAN);

        // Step 15. Run the time marches on steps.

Review comment (suggestion):
Nit:

```suggestion
            if let Err(error) = player.lock().unwrap().seek(time) {
                error!("Seek error {error:?}");
```

Code after:
                    nearest_seekable_distance = distance;
                    nearest_seekable_position = end;
                }
            }
        }
        let time = if in_seekable_range {
            time
        } else {
            nearest_seekable_position
        };

        // Step 9. If the approximate-for-speed flag is set, adjust the new playback position to a
        // value that will allow for playback to resume promptly. If new playback position before
        // this step is before current playback position, then the adjusted new playback position
        // must also be before the current playback position. Similarly, if the new playback
        // position before this step is after current playback position, then the adjusted new
        // playback position must also be after the current playback position.
        // TODO: Note that servo-media with gstreamer does not support inaccurate seeking for now.

        // Step 10. Queue a media element task given the media element to fire an event named
        // seeking at the element.
        self.queue_media_element_task_to_fire_event(atom!("seeking"));

        // Step 11. Set the current playback position to the new playback position.
        self.current_playback_position.set(time);

        if let Some(ref player) = *self.player.borrow() {
            if let Err(error) = player.lock().unwrap().seek(time) {
                error!("Could not seek player: {error:?}");
            }
        }

        self.current_seek_position.set(time);

        // Step 12. Wait until the user agent has established whether or not the media data for the
        // new playback position is available, and, if it is, until it has decoded enough data to
        // play back that position.
        // The rest of the steps are handled when the media engine signals a ready state change or
        // otherwise satisfies seek completion and signals a position change.
    }

    /// <https://html.spec.whatwg.org/multipage/#dom-media-seek>
    fn seek_end(&self) {
        // Any time the user agent provides a stable state, the official playback position must be
        // set to the current playback position.
        self.official_playback_position
            .set(self.current_playback_position.get());

        // Step 14. Set the seeking IDL attribute to false.
        self.seeking.set(false);