Skip to content
Permalink
Browse files

Default media session actions

  • Loading branch information
ferjm committed Nov 12, 2019
1 parent 68baabb commit 9da1dd359290bf59a0990a8664b58b5cfbb1f091
@@ -1913,6 +1913,15 @@ impl HTMLMediaElement {
self.media_element_load_algorithm();
}
}

fn send_media_session_event(&self, event: MediaSessionEvent) {
let global = self.global();
let media_session = global.as_window().Navigator().MediaSession();

media_session.register_media_instance(&self);

media_session.send_event(event);
}
}

// XXX Placeholder for [https://github.com/servo/servo/issues/22293]
@@ -2,8 +2,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use crate::compartments::{AlreadyInCompartment, InCompartment};
use crate::dom::bindings::callback::ExceptionHandling;
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::HTMLMediaElementBinding::HTMLMediaElementMethods;
use crate::dom::bindings::codegen::Bindings::MediaSessionBinding;
use crate::dom::bindings::codegen::Bindings::MediaSessionBinding::MediaSessionAction;
use crate::dom::bindings::codegen::Bindings::MediaSessionBinding::MediaSessionActionHandler;
@@ -61,15 +63,38 @@ impl MediaSession {
)
}

pub fn register_media_instance(&self, media_instance: &HTMLMediaElement) {
self.media_instance.set(Some(media_instance));
}

pub fn handle_action(&self, action: MediaSessionActionType) {
println!("HANDLE ACTION {:?}", action);
debug!("Handle media session action {:?} {:?}", action);
if let Some(handler) = self.action_handlers.borrow().get(&action) {
if handler.Call__(ExceptionHandling::Report).is_err() {
warn!("Error calling MediaSessionActionHandler callback");
}
return;
}
// TODO default action.

// Default action.
if let Some(media) = self.media_instance.get() {
match action {
MediaSessionActionType::Play => {
let in_compartment_proof = AlreadyInCompartment::assert(&self.global());
media.Play(InCompartment::Already(&in_compartment_proof));
},
MediaSessionActionType::Pause => {
media.Pause();
},
MediaSessionActionType::SeekBackward => {},
MediaSessionActionType::SeekForward => {},
MediaSessionActionType::PreviousTrack => {},
MediaSessionActionType::NextTrack => {},
MediaSessionActionType::SkipAd => {},
MediaSessionActionType::Stop => {},
MediaSessionActionType::SeekTo => {},
}
}
}

pub fn send_event(&self, event: MediaSessionEvent) {
@@ -256,7 +256,7 @@ pub enum ScriptMsg {
GetScreenAvailSize(IpcSender<DeviceIntSize>),
/// Notifies the constellation about media session events
/// (i.e. when there is metadata for the active media session, playback state changes...).
MediaSessionEvent(BrowsingContextId, MediaSessionEvent)
MediaSessionEvent(BrowsingContextId, MediaSessionEvent),
}

impl fmt::Debug for ScriptMsg {

0 comments on commit 9da1dd3

Please sign in to comment.
You can’t perform that action at this time.