diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2019-11-20 12:31:29 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-20 12:31:29 -0500 |
commit | f6348b8b54a1586b291bd4858df94050e05706c0 (patch) | |
tree | 4a1dd8e99f310609028b179b66f0eb74915b599e /components/embedder_traits/lib.rs | |
parent | 7da8d75a7e2a1f07bd09b8fb03b404ce4392a2af (diff) | |
parent | 9f77ea11651f2d987d84e01e222f2382d525b868 (diff) | |
download | servo-f6348b8b54a1586b291bd4858df94050e05706c0.tar.gz servo-f6348b8b54a1586b291bd4858df94050e05706c0.zip |
Auto merge of #24499 - ferjm:media.session.api, r=Manishearth
Media Session API
- [X] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #24172
- [x] There are tests for these changes
This PR introduces all the pieces required to prove an end to end media session flow with Android as a test platform.
Diffstat (limited to 'components/embedder_traits/lib.rs')
-rw-r--r-- | components/embedder_traits/lib.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/components/embedder_traits/lib.rs b/components/embedder_traits/lib.rs index 949b3ba5acb..9d4e56dd297 100644 --- a/components/embedder_traits/lib.rs +++ b/components/embedder_traits/lib.rs @@ -162,6 +162,9 @@ pub enum EmbedderMsg { Shutdown, /// Report a complete sampled profile ReportProfile(Vec<u8>), + /// Notifies the embedder about media session events + /// (i.e. when there is metadata for the active media session, playback state changes...). + MediaSessionEvent(MediaSessionEvent), } impl Debug for EmbedderMsg { @@ -194,6 +197,7 @@ impl Debug for EmbedderMsg { EmbedderMsg::AllowOpeningBrowser(..) => write!(f, "AllowOpeningBrowser"), EmbedderMsg::BrowserCreated(..) => write!(f, "BrowserCreated"), EmbedderMsg::ReportProfile(..) => write!(f, "ReportProfile"), + EmbedderMsg::MediaSessionEvent(..) => write!(f, "MediaSessionEvent"), } } } @@ -202,3 +206,45 @@ impl Debug for EmbedderMsg { /// the `String` content is expected to be extension (e.g, "doc", without the prefixing ".") #[derive(Clone, Debug, Deserialize, Serialize)] pub struct FilterPattern(pub String); + +/// https://w3c.github.io/mediasession/#mediametadata +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct MediaMetadata { + /// Title + pub title: String, + /// Artist + pub artist: String, + /// Album + pub album: String, +} + +impl MediaMetadata { + pub fn new(title: String) -> Self { + Self { + title, + artist: "".to_owned(), + album: "".to_owned(), + } + } +} + +/// 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_ = 1, + /// The browsing context is currently playing media and it can be paused. + Playing, + /// The browsing context has paused media and it can be resumed. + Paused, +} + +/// Type of events sent from script to the embedder about the media session. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub enum MediaSessionEvent { + /// Indicates that the media metadata is available. + SetMetadata(MediaMetadata), + /// Indicates that the playback state has changed. + PlaybackStateChange(MediaSessionPlaybackState), +} |