HTMLMediaElement playing attribute

This commit is contained in:
Fernando Jiménez Moreno 2018-11-02 10:07:12 +01:00
parent 5da1069491
commit f98da2e7b7
4 changed files with 27 additions and 19 deletions

View file

@ -33,6 +33,7 @@ use crate::dom::mediaerror::MediaError;
use crate::dom::node::{document_from_node, window_from_node, Node, NodeDamage, UnbindContext};
use crate::dom::performanceresourcetiming::InitiatorType;
use crate::dom::promise::Promise;
use crate::dom::timeranges::{TimeRanges, TimeRangesContainer};
use crate::dom::virtualmethods::VirtualMethods;
use crate::fetch::FetchCanceller;
use crate::microtask::{Microtask, MicrotaskRunnable};
@ -182,6 +183,9 @@ pub struct HTMLMediaElement {
seeking: Cell<bool>,
/// URL of the media resource, if any.
resource_url: DomRefCell<Option<ServoUrl>>,
/// https://html.spec.whatwg.org/multipage/#dom-media-played
#[ignore_malloc_size_of = "Rc"]
played: Rc<DomRefCell<TimeRangesContainer>>,
}
/// <https://html.spec.whatwg.org/multipage/#dom-media-networkstate>
@ -233,6 +237,7 @@ impl HTMLMediaElement {
default_playback_start_position: Cell::new(0.),
seeking: Cell::new(false),
resource_url: DomRefCell::new(None),
played: Rc::new(DomRefCell::new(TimeRangesContainer::new())),
}
}
@ -1186,7 +1191,12 @@ impl HTMLMediaElement {
// XXX Steps 12 and 13 require audio and video tracks support.
},
PlayerEvent::PositionChanged(position) => {
self.playback_position.set(position as f64);
let position = position as f64;
let _ = self
.played
.borrow_mut()
.add(self.playback_position.get(), position);
self.playback_position.set(position);
},
PlayerEvent::StateChanged(ref state) => match *state {
PlaybackState::Paused => {
@ -1356,6 +1366,11 @@ impl HTMLMediaElementMethods for HTMLMediaElement {
fn FastSeek(&self, time: Finite<f64>) {
self.seek(*time, /* approximat_for_speed */ true);
}
// https://html.spec.whatwg.org/multipage/#dom-media-played
fn Played(&self) -> DomRoot<TimeRanges> {
TimeRanges::new(self.global().as_window(), self.played.clone())
}
}
impl VirtualMethods for HTMLMediaElement {

View file

@ -12,6 +12,7 @@ use crate::dom::bindings::root::DomRoot;
use crate::dom::window::Window;
use dom_struct::dom_struct;
use std::fmt;
use std::rc::Rc;
#[derive(JSTraceable, MallocSizeOf)]
struct TimeRange {
@ -127,23 +128,27 @@ impl TimeRangesContainer {
#[dom_struct]
pub struct TimeRanges {
reflector_: Reflector,
ranges: DomRefCell<TimeRangesContainer>,
#[ignore_malloc_size_of = "Rc"]
ranges: Rc<DomRefCell<TimeRangesContainer>>,
}
//XXX(ferjm) We'll get warnings about unused methods until we use this
// on the media element implementation.
#[allow(dead_code)]
impl TimeRanges {
fn new_inherited() -> TimeRanges {
fn new_inherited(ranges: Rc<DomRefCell<TimeRangesContainer>>) -> TimeRanges {
Self {
reflector_: Reflector::new(),
ranges: DomRefCell::new(TimeRangesContainer::new()),
ranges,
}
}
pub fn new(window: &Window) -> DomRoot<TimeRanges> {
pub fn new(
window: &Window,
ranges: Rc<DomRefCell<TimeRangesContainer>>,
) -> DomRoot<TimeRanges> {
reflect_dom_object(
Box::new(TimeRanges::new_inherited()),
Box::new(TimeRanges::new_inherited(ranges)),
window,
TimeRangesBinding::Wrap,
)

View file

@ -44,7 +44,7 @@ interface HTMLMediaElement : HTMLElement {
readonly attribute boolean paused;
// attribute double defaultPlaybackRate;
// attribute double playbackRate;
// readonly attribute TimeRanges played;
readonly attribute TimeRanges played;
// readonly attribute TimeRanges seekable;
// readonly attribute boolean ended;
[CEReactions] attribute boolean autoplay;