mirror of
https://github.com/servo/servo.git
synced 2025-06-16 12:24:29 +00:00
Setter and getter for HTMLMediaElement.currentTime
This commit is contained in:
parent
abc0f50d20
commit
2db141fb8b
2 changed files with 56 additions and 7 deletions
|
@ -16,6 +16,7 @@ use dom::bindings::codegen::InheritTypes::{ElementTypeId, HTMLElementTypeId};
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLMediaElementTypeId, NodeTypeId};
|
use dom::bindings::codegen::InheritTypes::{HTMLMediaElementTypeId, NodeTypeId};
|
||||||
use dom::bindings::error::{Error, ErrorResult};
|
use dom::bindings::error::{Error, ErrorResult};
|
||||||
use dom::bindings::inheritance::Castable;
|
use dom::bindings::inheritance::Castable;
|
||||||
|
use dom::bindings::num::Finite;
|
||||||
use dom::bindings::refcounted::Trusted;
|
use dom::bindings::refcounted::Trusted;
|
||||||
use dom::bindings::reflector::DomObject;
|
use dom::bindings::reflector::DomObject;
|
||||||
use dom::bindings::root::{DomRoot, LayoutDom, MutNullableDom};
|
use dom::bindings::root::{DomRoot, LayoutDom, MutNullableDom};
|
||||||
|
@ -169,6 +170,10 @@ pub struct HTMLMediaElement {
|
||||||
show_poster: Cell<bool>,
|
show_poster: Cell<bool>,
|
||||||
/// https://html.spec.whatwg.org/multipage/#dom-media-duration
|
/// https://html.spec.whatwg.org/multipage/#dom-media-duration
|
||||||
duration: Cell<f64>,
|
duration: Cell<f64>,
|
||||||
|
/// https://html.spec.whatwg.org/multipage/media.html#official-playback-position
|
||||||
|
playback_position: Cell<f64>,
|
||||||
|
/// https://html.spec.whatwg.org/multipage/media.html#default-playback-start-position
|
||||||
|
default_playback_start_position: Cell<f64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://html.spec.whatwg.org/multipage/#dom-media-networkstate>
|
/// <https://html.spec.whatwg.org/multipage/#dom-media-networkstate>
|
||||||
|
@ -216,6 +221,8 @@ impl HTMLMediaElement {
|
||||||
fetch_canceller: DomRefCell::new(Default::default()),
|
fetch_canceller: DomRefCell::new(Default::default()),
|
||||||
show_poster: Cell::new(true),
|
show_poster: Cell::new(true),
|
||||||
duration: Cell::new(f64::NAN),
|
duration: Cell::new(f64::NAN),
|
||||||
|
playback_position: Cell::new(0.),
|
||||||
|
default_playback_start_position: Cell::new(0.),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -961,7 +968,11 @@ impl HTMLMediaElement {
|
||||||
self.media_element_load_algorithm();
|
self.media_element_load_algorithm();
|
||||||
}
|
}
|
||||||
|
|
||||||
// servo media player
|
// https://html.spec.whatwg.org/multipage/#dom-media-seek
|
||||||
|
fn seek(&self, _time: f64, _approximate_for_speed: bool) {
|
||||||
|
// XXX
|
||||||
|
}
|
||||||
|
|
||||||
fn setup_media_player(&self) -> Result<(), ServoMediaError> {
|
fn setup_media_player(&self) -> Result<(), ServoMediaError> {
|
||||||
let (action_sender, action_receiver) = ipc::channel().unwrap();
|
let (action_sender, action_receiver) = ipc::channel().unwrap();
|
||||||
|
|
||||||
|
@ -1004,8 +1015,7 @@ impl HTMLMediaElement {
|
||||||
// XXX(ferjm) Update the timeline offset.
|
// XXX(ferjm) Update the timeline offset.
|
||||||
|
|
||||||
// Step 3.
|
// Step 3.
|
||||||
// XXX(ferjm) Set the current and official playback positions
|
self.playback_position.set(0.);
|
||||||
// to the earliest possible position.
|
|
||||||
|
|
||||||
// Step 4.
|
// Step 4.
|
||||||
if let Some(duration) = metadata.duration {
|
if let Some(duration) = metadata.duration {
|
||||||
|
@ -1028,7 +1038,27 @@ impl HTMLMediaElement {
|
||||||
// Step 6.
|
// Step 6.
|
||||||
self.change_ready_state(ReadyState::HaveMetadata);
|
self.change_ready_state(ReadyState::HaveMetadata);
|
||||||
|
|
||||||
// XXX(ferjm) Steps 7 to 13.
|
// Step 7.
|
||||||
|
let mut _jumped = false;
|
||||||
|
|
||||||
|
// Step 8.
|
||||||
|
if self.default_playback_start_position.get() > 0. {
|
||||||
|
self.seek(self.default_playback_start_position.get(), /* approximate_for_speed*/ false);
|
||||||
|
_jumped = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 9.
|
||||||
|
self.default_playback_start_position.set(0.);
|
||||||
|
|
||||||
|
// Steps 10 and 11.
|
||||||
|
// XXX(ferjm) Implement parser for
|
||||||
|
// https://www.w3.org/TR/media-frags/#media-fragment-syntax
|
||||||
|
// https://github.com/servo/media/issues/156
|
||||||
|
|
||||||
|
// XXX Steps 12 and 13 require audio and video tracks support.
|
||||||
|
},
|
||||||
|
PlayerEvent::PositionChanged(position) => {
|
||||||
|
self.playback_position.set(position as f64);
|
||||||
},
|
},
|
||||||
PlayerEvent::StateChanged(ref state) => match *state {
|
PlayerEvent::StateChanged(ref state) => match *state {
|
||||||
PlaybackState::Paused => {
|
PlaybackState::Paused => {
|
||||||
|
@ -1157,6 +1187,25 @@ impl HTMLMediaElementMethods for HTMLMediaElement {
|
||||||
fn Duration(&self) -> f64 {
|
fn Duration(&self) -> f64 {
|
||||||
self.duration.get()
|
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 {
|
||||||
|
self.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.playback_position.set(*time);
|
||||||
|
self.seek(*time, /* approximate_for_speed */ false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VirtualMethods for HTMLMediaElement {
|
impl VirtualMethods for HTMLMediaElement {
|
||||||
|
|
|
@ -37,7 +37,7 @@ interface HTMLMediaElement : HTMLElement {
|
||||||
// readonly attribute boolean seeking;
|
// readonly attribute boolean seeking;
|
||||||
|
|
||||||
// playback state
|
// playback state
|
||||||
// attribute double currentTime;
|
attribute double currentTime;
|
||||||
// void fastSeek(double time);
|
// void fastSeek(double time);
|
||||||
readonly attribute unrestricted double duration;
|
readonly attribute unrestricted double duration;
|
||||||
// Date getStartDate();
|
// Date getStartDate();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue