mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
MediaSession: refactor embedder API. Fix Android build
This commit is contained in:
parent
89d9e3ad78
commit
7ca74d598c
5 changed files with 65 additions and 17 deletions
|
@ -219,10 +219,11 @@ pub struct MediaMetadata {
|
|||
}
|
||||
|
||||
/// https://w3c.github.io/mediasession/#enumdef-mediasessionplaybackstate
|
||||
#[repr(i32)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub enum MediaSessionPlaybackState {
|
||||
/// The browsing context does not specify whether it’s playing or paused.
|
||||
None_,
|
||||
None_ = 1,
|
||||
/// The browsing context has paused media and it can be resumed.
|
||||
Playing,
|
||||
/// The browsing context is currently playing media and it can be paused.
|
||||
|
|
|
@ -449,9 +449,9 @@ where
|
|||
error!("Failed to store profile: {}", e);
|
||||
}
|
||||
},
|
||||
EmbedderMsg::MediaSession(_) => {
|
||||
debug!("MediaSession received");
|
||||
// TODO(ferjm)
|
||||
EmbedderMsg::MediaSessionEvent(_) => {
|
||||
debug!("MediaSessionEvent received");
|
||||
// TODO(ferjm): MediaSession support for Glutin based browsers.
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ use servo::compositing::windowing::{
|
|||
WindowMethods,
|
||||
};
|
||||
use servo::embedder_traits::resources::{self, Resource, ResourceReaderMethods};
|
||||
use servo::embedder_traits::EmbedderMsg;
|
||||
use servo::embedder_traits::{EmbedderMsg, MediaSessionEvent};
|
||||
use servo::euclid::{Point2D, Rect, Scale, Size2D, Vector2D};
|
||||
use servo::keyboard_types::{Key, KeyState, KeyboardEvent};
|
||||
use servo::msg::constellation_msg::TraversalDirection;
|
||||
|
@ -42,7 +42,6 @@ thread_local! {
|
|||
/// It will be called to notify embedder that some events are available,
|
||||
/// and that perform_updates need to be called
|
||||
pub use servo::embedder_traits::EventLoopWaker;
|
||||
pub use servo::embedder_traits::MediaSessionEvent;
|
||||
|
||||
pub struct InitOptions {
|
||||
pub args: Vec<String>,
|
||||
|
@ -127,12 +126,19 @@ pub trait HostTrait {
|
|||
fn on_shutdown_complete(&self);
|
||||
/// A text input is focused.
|
||||
fn on_ime_state_changed(&self, show: bool);
|
||||
/// Gets sytem clipboard contents
|
||||
/// Gets sytem clipboard contents.
|
||||
fn get_clipboard_contents(&self) -> Option<String>;
|
||||
/// Sets system clipboard contents
|
||||
/// Sets system clipboard contents.
|
||||
fn set_clipboard_contents(&self, contents: String);
|
||||
/// Called when there is a new media session event.
|
||||
fn on_media_session_event(&self, event: MediaSessionEvent);
|
||||
/// Called when we get the media session metadata/
|
||||
fn on_media_session_metadata(
|
||||
&self,
|
||||
title: String,
|
||||
artist: Option<String>,
|
||||
album: Option<String>,
|
||||
);
|
||||
/// Called when the media sessoin playback state changes.
|
||||
fn on_media_session_playback_state_change(&self, state: i32);
|
||||
}
|
||||
|
||||
pub struct ServoGlue {
|
||||
|
@ -585,7 +591,19 @@ impl ServoGlue {
|
|||
self.callbacks.host_callbacks.on_ime_state_changed(false);
|
||||
},
|
||||
EmbedderMsg::MediaSessionEvent(event) => {
|
||||
self.callbacks.host_callbacks.on_media_session_event(event);
|
||||
match event {
|
||||
MediaSessionEvent::SetMetadata(metadata) => {
|
||||
self.callbacks.host_callbacks.on_media_session_metadata(
|
||||
metadata.title,
|
||||
metadata.artist,
|
||||
metadata.album,
|
||||
)
|
||||
},
|
||||
MediaSessionEvent::PlaybackStateChange(state) => self
|
||||
.callbacks
|
||||
.host_callbacks
|
||||
.on_media_session_playback_state_change(state as i32),
|
||||
};
|
||||
},
|
||||
EmbedderMsg::Status(..) |
|
||||
EmbedderMsg::SelectFiles(..) |
|
||||
|
|
|
@ -216,8 +216,9 @@ pub struct CHostCallbacks {
|
|||
pub on_ime_state_changed: extern "C" fn(show: bool),
|
||||
pub get_clipboard_contents: extern "C" fn() -> *const c_char,
|
||||
pub set_clipboard_contents: extern "C" fn(contents: *const c_char),
|
||||
// TODO(ferjm) pass C representation of media event.
|
||||
pub on_media_session_event: extern "C" fn(),
|
||||
pub on_media_session_metadata:
|
||||
extern "C" fn(title: *const c_char, album: *const c_char, artist: *const c_char),
|
||||
pub on_media_session_playback_state_change: extern "C" fn(state: i32),
|
||||
}
|
||||
|
||||
/// Servo options
|
||||
|
@ -711,8 +712,24 @@ impl HostTrait for HostCallbacks {
|
|||
(self.0.set_clipboard_contents)(contents.as_ptr());
|
||||
}
|
||||
|
||||
fn on_media_session_event(&self, event: MediaSessionEvent) {
|
||||
debug!("on_media_session_event (event: {:?})", event);
|
||||
(self.0.on_media_session_event)();
|
||||
fn on_media_session_metadata(
|
||||
&self,
|
||||
title: String,
|
||||
artist: Option<String>,
|
||||
album: Option<String>,
|
||||
) {
|
||||
debug!(
|
||||
"on_media_session_metadata ({:?} {:?} {:?})",
|
||||
title, artist, album
|
||||
);
|
||||
let title = CString::new(title).expect("Can't create string");
|
||||
let artist = CString::new(artist.unwrap_or(String::new())).expect("Can't create string");
|
||||
let album = CString::new(album.unwrap_or(String::new())).expect("Can't create string");
|
||||
(self.0.on_media_session_metadata)(title.as_ptr(), artist.as_ptr(), album.as_ptr());
|
||||
}
|
||||
|
||||
fn on_media_session_playback_state_change(&self, state: i32) {
|
||||
debug!("on_media_session_playback_state_change {:?}", state);
|
||||
(self.0.on_media_session_playback_state_change)(state);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,9 @@ use jni::{errors, JNIEnv, JavaVM};
|
|||
use libc::{dup2, pipe, read};
|
||||
use log::Level;
|
||||
use simpleservo::{self, gl_glue, ServoGlue, SERVO};
|
||||
use simpleservo::{Coordinates, EventLoopWaker, HostTrait, InitOptions, VRInitOptions};
|
||||
use simpleservo::{
|
||||
Coordinates, EventLoopWaker, HostTrait, InitOptions, MediaSessionEvent, VRInitOptions,
|
||||
};
|
||||
use std::os::raw::{c_char, c_int, c_void};
|
||||
use std::ptr::{null, null_mut};
|
||||
use std::sync::Arc;
|
||||
|
@ -508,6 +510,16 @@ impl HostTrait for HostCallbacks {
|
|||
}
|
||||
|
||||
fn set_clipboard_contents(&self, _contents: String) {}
|
||||
|
||||
fn on_media_session_metadata(
|
||||
&self,
|
||||
_title: String,
|
||||
_artist: Option<String>,
|
||||
_album: Option<String>,
|
||||
) {
|
||||
}
|
||||
|
||||
fn on_media_session_playback_state_change(&self, state: i32) {}
|
||||
}
|
||||
|
||||
fn initialize_android_glue(env: &JNIEnv, activity: JObject) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue