Skip to content

Commit

Permalink
Implement basic <source> support for HtmlMediaElement
Browse files Browse the repository at this point in the history
The spec has a complicated algorithm for selecting a <source>
element among multiple <source> children of a HtmlMediaElement
where it loops over all of them, tries each and takes the first
where "everything works out".

This commit implements a much simpler and restricted approach by
just taking the first <source> child, and if that fails,
failing altogether, without looking at any further children.

This is an improvement over the current status and makes gifv
items on imgur playable, although it doesn't mean full <source>
support.
  • Loading branch information
est31 committed Oct 12, 2018
1 parent 5f463d3 commit af0f7db
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions components/script/dom/htmlmediaelement.rs
Expand Up @@ -9,6 +9,7 @@ use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods;
use dom::bindings::codegen::Bindings::HTMLMediaElementBinding::CanPlayTypeResult;
use dom::bindings::codegen::Bindings::HTMLMediaElementBinding::HTMLMediaElementConstants;
use dom::bindings::codegen::Bindings::HTMLMediaElementBinding::HTMLMediaElementMethods;
use dom::bindings::codegen::Bindings::HTMLSourceElementBinding::HTMLSourceElementMethods;
use dom::bindings::codegen::Bindings::MediaErrorBinding::MediaErrorConstants::*;
use dom::bindings::codegen::Bindings::MediaErrorBinding::MediaErrorMethods;
use dom::bindings::codegen::InheritTypes::{ElementTypeId, HTMLElementTypeId};
Expand Down Expand Up @@ -633,10 +634,28 @@ impl HTMLMediaElement {
// of the cleanup in case of failure itself.
self.resource_fetch_algorithm(Resource::Url(url_record));
},
Mode::Children(_source) => {
// Step 9.children.
// Step 9.children.
Mode::Children(source) => {
// This is only a partial implementation
// FIXME: https://github.com/servo/servo/issues/21481
self.queue_dedicated_media_source_failure_steps()
let src = source.Src();
// Step 9.attr.2.
if src.is_empty() {
source.upcast::<EventTarget>().fire_event(atom!("error"));
self.queue_dedicated_media_source_failure_steps();
return;
}
// Step 9.attr.3.
let url_record = match base_url.join(&src) {
Ok(url) => url,
Err(_) => {
source.upcast::<EventTarget>().fire_event(atom!("error"));
self.queue_dedicated_media_source_failure_steps();
return;
},
};
// Step 9.attr.8.
self.resource_fetch_algorithm(Resource::Url(url_record));
},
}
}
Expand Down

0 comments on commit af0f7db

Please sign in to comment.