mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Fire AudioScheduledSourceNode.onended when playback stops
This commit is contained in:
parent
c9ff1b9f57
commit
acb03603b6
4 changed files with 37 additions and 7 deletions
|
@ -6,10 +6,15 @@ use dom::baseaudiocontext::BaseAudioContext;
|
|||
use dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions;
|
||||
use dom::bindings::codegen::Bindings::AudioScheduledSourceNodeBinding::AudioScheduledSourceNodeMethods;
|
||||
use dom::bindings::error::{Error, Fallible};
|
||||
use dom::bindings::inheritance::Castable;
|
||||
use dom::bindings::num::Finite;
|
||||
use dom::bindings::refcounted::Trusted;
|
||||
use dom::bindings::reflector::DomObject;
|
||||
use dom_struct::dom_struct;
|
||||
use servo_media::audio::node::{AudioNodeMessage, AudioNodeInit, AudioScheduledSourceNodeMessage};
|
||||
use servo_media::audio::node::OnEndedCallback;
|
||||
use std::cell::Cell;
|
||||
use task_source::{TaskSource, TaskSourceName};
|
||||
|
||||
#[dom_struct]
|
||||
pub struct AudioScheduledSourceNode {
|
||||
|
@ -51,7 +56,6 @@ impl AudioScheduledSourceNode {
|
|||
|
||||
impl AudioScheduledSourceNodeMethods for AudioScheduledSourceNode {
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audioscheduledsourcenode-onended
|
||||
// XXX We should dispatch this when we reach the end. Depends on servo-media #82.
|
||||
event_handler!(ended, GetOnended, SetOnended);
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audioscheduledsourcenode-start
|
||||
|
@ -59,6 +63,32 @@ impl AudioScheduledSourceNodeMethods for AudioScheduledSourceNode {
|
|||
if self.started.get() || self.stopped.get() {
|
||||
return Err(Error::InvalidState);
|
||||
}
|
||||
|
||||
let this = Trusted::new(self);
|
||||
let global = self.global();
|
||||
let window = global.as_window();
|
||||
let task_source = window.dom_manipulation_task_source();
|
||||
let canceller = window.task_canceller(TaskSourceName::DOMManipulation);
|
||||
let callback = OnEndedCallback::new(move || {
|
||||
let _ = task_source.queue_with_canceller(
|
||||
task!(ended: move || {
|
||||
let this = this.root();
|
||||
let global = this.global();
|
||||
let window = global.as_window();
|
||||
window.dom_manipulation_task_source().queue_simple_event(
|
||||
this.upcast(),
|
||||
atom!("ended"),
|
||||
&window
|
||||
);
|
||||
}),
|
||||
&canceller,
|
||||
);
|
||||
});
|
||||
|
||||
self.node().message(
|
||||
AudioNodeMessage::AudioScheduledSourceNode(
|
||||
AudioScheduledSourceNodeMessage::RegisterOnEndedCallback(callback)));
|
||||
|
||||
self.started.set(true);
|
||||
self.node
|
||||
.message(AudioNodeMessage::AudioScheduledSourceNode(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue