mirror of
https://github.com/servo/servo.git
synced 2025-06-12 10:24:43 +00:00
extended MediaSessionEvent with SetPositionState
This commit is contained in:
parent
3e83b0bd25
commit
8bdee36bb8
2 changed files with 30 additions and 1 deletions
|
@ -240,6 +240,24 @@ pub enum MediaSessionPlaybackState {
|
||||||
Paused,
|
Paused,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// https://w3c.github.io/mediasession/#dictdef-mediapositionstate
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
pub struct MediaPositionState {
|
||||||
|
pub duration: Option<f64>,
|
||||||
|
pub playback_rate: Option<f64>,
|
||||||
|
pub position: Option<f64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MediaPositionState {
|
||||||
|
pub fn new(duration: f64, playback_rate: f64, position: f64) -> Self {
|
||||||
|
Self {
|
||||||
|
duration,
|
||||||
|
playback_rate,
|
||||||
|
position,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Type of events sent from script to the embedder about the media session.
|
/// Type of events sent from script to the embedder about the media session.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub enum MediaSessionEvent {
|
pub enum MediaSessionEvent {
|
||||||
|
@ -247,4 +265,6 @@ pub enum MediaSessionEvent {
|
||||||
SetMetadata(MediaMetadata),
|
SetMetadata(MediaMetadata),
|
||||||
/// Indicates that the playback state has changed.
|
/// Indicates that the playback state has changed.
|
||||||
PlaybackStateChange(MediaSessionPlaybackState),
|
PlaybackStateChange(MediaSessionPlaybackState),
|
||||||
|
/// Indicates that the position state is set.
|
||||||
|
SetPositionState(MediaPositionState),
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ use crate::script_thread::ScriptThread;
|
||||||
use crate::task_source::TaskSource;
|
use crate::task_source::TaskSource;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use embedder_traits::resources::{self, Resource as EmbedderResource};
|
use embedder_traits::resources::{self, Resource as EmbedderResource};
|
||||||
use embedder_traits::{MediaSessionEvent, MediaSessionPlaybackState};
|
use embedder_traits::{MediaPositionState, MediaSessionEvent, MediaSessionPlaybackState};
|
||||||
use euclid::default::Size2D;
|
use euclid::default::Size2D;
|
||||||
use headers::{ContentLength, ContentRange, HeaderMapExt};
|
use headers::{ContentLength, ContentRange, HeaderMapExt};
|
||||||
use html5ever::{LocalName, Prefix};
|
use html5ever::{LocalName, Prefix};
|
||||||
|
@ -1780,6 +1780,15 @@ impl HTMLMediaElement {
|
||||||
.add(self.playback_position.get(), position);
|
.add(self.playback_position.get(), position);
|
||||||
self.playback_position.set(position);
|
self.playback_position.set(position);
|
||||||
self.time_marches_on();
|
self.time_marches_on();
|
||||||
|
let media_position_state =
|
||||||
|
MediaPositionState::new(self.duration.get(), self.playbackRate.get(), position);
|
||||||
|
debug!(
|
||||||
|
"Sending media session event set position state {:?}",
|
||||||
|
media_position_state
|
||||||
|
);
|
||||||
|
self.send_media_session_event(MediaSessionEvent::SetPositionState(
|
||||||
|
media_position_state,
|
||||||
|
));
|
||||||
},
|
},
|
||||||
PlayerEvent::SeekData(p, ref seek_lock) => {
|
PlayerEvent::SeekData(p, ref seek_lock) => {
|
||||||
self.fetch_request(Some(p), Some(seek_lock.clone()));
|
self.fetch_request(Some(p), Some(seek_lock.clone()));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue