mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Default media session actions
This commit is contained in:
parent
68baabba63
commit
9da1dd3592
3 changed files with 37 additions and 3 deletions
|
@ -1913,6 +1913,15 @@ impl HTMLMediaElement {
|
||||||
self.media_element_load_algorithm();
|
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]
|
// 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
|
* 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/. */
|
* 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::callback::ExceptionHandling;
|
||||||
use crate::dom::bindings::cell::DomRefCell;
|
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;
|
||||||
use crate::dom::bindings::codegen::Bindings::MediaSessionBinding::MediaSessionAction;
|
use crate::dom::bindings::codegen::Bindings::MediaSessionBinding::MediaSessionAction;
|
||||||
use crate::dom::bindings::codegen::Bindings::MediaSessionBinding::MediaSessionActionHandler;
|
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) {
|
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 let Some(handler) = self.action_handlers.borrow().get(&action) {
|
||||||
if handler.Call__(ExceptionHandling::Report).is_err() {
|
if handler.Call__(ExceptionHandling::Report).is_err() {
|
||||||
warn!("Error calling MediaSessionActionHandler callback");
|
warn!("Error calling MediaSessionActionHandler callback");
|
||||||
}
|
}
|
||||||
return;
|
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) {
|
pub fn send_event(&self, event: MediaSessionEvent) {
|
||||||
|
|
|
@ -256,7 +256,7 @@ pub enum ScriptMsg {
|
||||||
GetScreenAvailSize(IpcSender<DeviceIntSize>),
|
GetScreenAvailSize(IpcSender<DeviceIntSize>),
|
||||||
/// Notifies the constellation about media session events
|
/// Notifies the constellation about media session events
|
||||||
/// (i.e. when there is metadata for the active media session, playback state changes...).
|
/// (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 {
|
impl fmt::Debug for ScriptMsg {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue