mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Introduce CMediaSessionPlaybackState and CMediaSessionActionType
This commit is contained in:
parent
d5200ba453
commit
b01e3fdc7e
10 changed files with 71 additions and 41 deletions
|
@ -7,7 +7,8 @@ extern crate log;
|
||||||
|
|
||||||
pub mod gl_glue;
|
pub mod gl_glue;
|
||||||
|
|
||||||
pub use servo::script_traits::MouseButton;
|
pub use servo::embedder_traits::MediaSessionPlaybackState;
|
||||||
|
pub use servo::script_traits::{MediaSessionActionType, MouseButton};
|
||||||
|
|
||||||
use getopts::Options;
|
use getopts::Options;
|
||||||
use servo::compositing::windowing::{
|
use servo::compositing::windowing::{
|
||||||
|
@ -133,7 +134,7 @@ pub trait HostTrait {
|
||||||
/// Called when we get the media session metadata/
|
/// Called when we get the media session metadata/
|
||||||
fn on_media_session_metadata(&self, title: String, artist: String, album: String);
|
fn on_media_session_metadata(&self, title: String, artist: String, album: String);
|
||||||
/// Called when the media session playback state changes.
|
/// Called when the media session playback state changes.
|
||||||
fn on_media_session_playback_state_change(&self, state: i32);
|
fn on_media_session_playback_state_change(&self, state: MediaSessionPlaybackState);
|
||||||
/// Called when the media session position state is set.
|
/// Called when the media session position state is set.
|
||||||
fn on_media_session_set_position_state(&self, duration: f64, position: f64, playback_rate: f64);
|
fn on_media_session_set_position_state(&self, duration: f64, position: f64, playback_rate: f64);
|
||||||
}
|
}
|
||||||
|
@ -472,9 +473,12 @@ impl ServoGlue {
|
||||||
self.process_event(WindowEvent::Keyboard(key_event))
|
self.process_event(WindowEvent::Keyboard(key_event))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn media_session_action(&mut self, action: i32) -> Result<(), &'static str> {
|
pub fn media_session_action(
|
||||||
|
&mut self,
|
||||||
|
action: MediaSessionActionType,
|
||||||
|
) -> Result<(), &'static str> {
|
||||||
info!("Media session action {:?}", action);
|
info!("Media session action {:?}", action);
|
||||||
self.process_event(WindowEvent::MediaSessionAction(action.into()))
|
self.process_event(WindowEvent::MediaSessionAction(action))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_event(&mut self, event: WindowEvent) -> Result<(), &'static str> {
|
fn process_event(&mut self, event: WindowEvent) -> Result<(), &'static str> {
|
||||||
|
@ -595,7 +599,7 @@ impl ServoGlue {
|
||||||
MediaSessionEvent::PlaybackStateChange(state) => self
|
MediaSessionEvent::PlaybackStateChange(state) => self
|
||||||
.callbacks
|
.callbacks
|
||||||
.host_callbacks
|
.host_callbacks
|
||||||
.on_media_session_playback_state_change(state as i32),
|
.on_media_session_playback_state_change(state),
|
||||||
MediaSessionEvent::SetPositionState(position_state) => self
|
MediaSessionEvent::SetPositionState(position_state) => self
|
||||||
.callbacks
|
.callbacks
|
||||||
.host_callbacks
|
.host_callbacks
|
||||||
|
|
|
@ -17,7 +17,8 @@ use env_logger;
|
||||||
use log::LevelFilter;
|
use log::LevelFilter;
|
||||||
use simpleservo::{self, gl_glue, ServoGlue, SERVO};
|
use simpleservo::{self, gl_glue, ServoGlue, SERVO};
|
||||||
use simpleservo::{
|
use simpleservo::{
|
||||||
Coordinates, EventLoopWaker, HostTrait, InitOptions, MouseButton, VRInitOptions,
|
Coordinates, EventLoopWaker, HostTrait, InitOptions, MediaSessionActionType,
|
||||||
|
MediaSessionPlaybackState, MouseButton, VRInitOptions,
|
||||||
};
|
};
|
||||||
use std::ffi::{CStr, CString};
|
use std::ffi::{CStr, CString};
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
|
@ -218,7 +219,7 @@ pub struct CHostCallbacks {
|
||||||
pub set_clipboard_contents: extern "C" fn(contents: *const c_char),
|
pub set_clipboard_contents: extern "C" fn(contents: *const c_char),
|
||||||
pub on_media_session_metadata:
|
pub on_media_session_metadata:
|
||||||
extern "C" fn(title: *const c_char, album: *const c_char, artist: *const c_char),
|
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),
|
pub on_media_session_playback_state_change: extern "C" fn(state: CMediaSessionPlaybackState),
|
||||||
pub on_media_session_set_position_state:
|
pub on_media_session_set_position_state:
|
||||||
extern "C" fn(duration: f64, position: f64, playback_rate: f64),
|
extern "C" fn(duration: f64, position: f64, playback_rate: f64),
|
||||||
}
|
}
|
||||||
|
@ -254,6 +255,52 @@ impl CMouseButton {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub enum CMediaSessionPlaybackState {
|
||||||
|
None = 1,
|
||||||
|
Playing,
|
||||||
|
Paused,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<MediaSessionPlaybackState> for CMediaSessionPlaybackState {
|
||||||
|
fn from(state: MediaSessionPlaybackState) -> Self {
|
||||||
|
match state {
|
||||||
|
MediaSessionPlaybackState::None_ => CMediaSessionPlaybackState::None,
|
||||||
|
MediaSessionPlaybackState::Playing => CMediaSessionPlaybackState::Playing,
|
||||||
|
MediaSessionPlaybackState::Paused => CMediaSessionPlaybackState::Paused,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub enum CMediaSessionActionType {
|
||||||
|
Play = 1,
|
||||||
|
Pause,
|
||||||
|
SeekBackward,
|
||||||
|
SeekForward,
|
||||||
|
PreviousTrack,
|
||||||
|
NextTrack,
|
||||||
|
SkipAd,
|
||||||
|
Stop,
|
||||||
|
SeekTo,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CMediaSessionActionType {
|
||||||
|
pub fn convert(&self) -> MediaSessionActionType {
|
||||||
|
match self {
|
||||||
|
CMediaSessionActionType::Play => MediaSessionActionType::Play,
|
||||||
|
CMediaSessionActionType::Pause => MediaSessionActionType::Pause,
|
||||||
|
CMediaSessionActionType::SeekBackward => MediaSessionActionType::SeekBackward,
|
||||||
|
CMediaSessionActionType::SeekForward => MediaSessionActionType::SeekForward,
|
||||||
|
CMediaSessionActionType::PreviousTrack => MediaSessionActionType::PreviousTrack,
|
||||||
|
CMediaSessionActionType::NextTrack => MediaSessionActionType::NextTrack,
|
||||||
|
CMediaSessionActionType::SkipAd => MediaSessionActionType::SkipAd,
|
||||||
|
CMediaSessionActionType::Stop => MediaSessionActionType::Stop,
|
||||||
|
CMediaSessionActionType::SeekTo => MediaSessionActionType::SeekTo,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The returned string is not freed. This will leak.
|
/// The returned string is not freed. This will leak.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn servo_version() -> *const c_char {
|
pub extern "C" fn servo_version() -> *const c_char {
|
||||||
|
@ -608,10 +655,10 @@ pub extern "C" fn click(x: f32, y: f32) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn media_session_action(action: i32) {
|
pub extern "C" fn media_session_action(action: CMediaSessionActionType) {
|
||||||
catch_any_panic(|| {
|
catch_any_panic(|| {
|
||||||
debug!("media_session_action");
|
debug!("media_session_action");
|
||||||
call(|s| s.media_session_action(action));
|
call(|s| s.media_session_action(action.convert()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -733,9 +780,9 @@ impl HostTrait for HostCallbacks {
|
||||||
(self.0.on_media_session_metadata)(title.as_ptr(), artist.as_ptr(), album.as_ptr());
|
(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) {
|
fn on_media_session_playback_state_change(&self, state: MediaSessionPlaybackState) {
|
||||||
debug!("on_media_session_playback_state_change {:?}", state);
|
debug!("on_media_session_playback_state_change {:?}", state);
|
||||||
(self.0.on_media_session_playback_state_change)(state);
|
(self.0.on_media_session_playback_state_change)(state.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_media_session_set_position_state(
|
fn on_media_session_set_position_state(
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
#include "BrowserPage.h"
|
#include "BrowserPage.h"
|
||||||
#include "BrowserPage.g.cpp"
|
#include "BrowserPage.g.cpp"
|
||||||
#include "DefaultUrl.h"
|
#include "DefaultUrl.h"
|
||||||
#include "MediaSession.h"
|
|
||||||
|
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
using namespace winrt::Windows::Foundation;
|
using namespace winrt::Windows::Foundation;
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
namespace winrt::servo {
|
|
||||||
enum PlaybackState {
|
|
||||||
NONE = 1,
|
|
||||||
PLAYING,
|
|
||||||
PAUSED
|
|
||||||
};
|
|
||||||
|
|
||||||
enum MediaSessionAction {
|
|
||||||
PLAY = 1,
|
|
||||||
PAUSE,
|
|
||||||
SEEK_BACKWARD,
|
|
||||||
SEEK_FORWARD,
|
|
||||||
PREVIOUS_TRACK,
|
|
||||||
NEXT_TRACK,
|
|
||||||
SKIP_AD,
|
|
||||||
STOP,
|
|
||||||
SEEK_TO
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -122,7 +122,6 @@
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="logs.h" />
|
<ClInclude Include="logs.h" />
|
||||||
<ClInclude Include="MediaSession.h" />
|
|
||||||
<ClInclude Include="pch.h" />
|
<ClInclude Include="pch.h" />
|
||||||
<ClInclude Include="App.h">
|
<ClInclude Include="App.h">
|
||||||
<DependentUpon>App.xaml</DependentUpon>
|
<DependentUpon>App.xaml</DependentUpon>
|
||||||
|
|
|
@ -40,9 +40,6 @@
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="DefaultUrl.h" />
|
<ClInclude Include="DefaultUrl.h" />
|
||||||
<ClInclude Include="XRPkgChecker.h" />
|
<ClInclude Include="XRPkgChecker.h" />
|
||||||
<ClInclude Include="MediaSession.h">
|
|
||||||
<Filter>ServoControl</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Image Include="Assets\Wide310x150Logo.scale-200.png">
|
<Image Include="Assets\Wide310x150Logo.scale-200.png">
|
||||||
|
|
|
@ -62,7 +62,8 @@ void on_media_session_metadata(const char *title, const char *album,
|
||||||
char2hstring(title), char2hstring(album), char2hstring(artist));
|
char2hstring(title), char2hstring(album), char2hstring(artist));
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_media_session_playback_state_change(const int state) {
|
void on_media_session_playback_state_change(
|
||||||
|
const capi::CMediaSessionPlaybackState state) {
|
||||||
return sServo->Delegate().OnServoMediaSessionPlaybackStateChange(state);
|
return sServo->Delegate().OnServoMediaSessionPlaybackStateChange(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,8 @@ public:
|
||||||
ServoDelegate &Delegate() { return mDelegate; }
|
ServoDelegate &Delegate() { return mDelegate; }
|
||||||
|
|
||||||
typedef capi::CMouseButton MouseButton;
|
typedef capi::CMouseButton MouseButton;
|
||||||
|
typedef capi::CMediaSessionActionType MediaSessionActionType;
|
||||||
|
typedef capi::CMediaSessionPlaybackState MediaSessionPlaybackState;
|
||||||
|
|
||||||
void PerformUpdates() { capi::perform_updates(); }
|
void PerformUpdates() { capi::perform_updates(); }
|
||||||
void DeInit() { capi::deinit(); }
|
void DeInit() { capi::deinit(); }
|
||||||
|
@ -88,7 +90,7 @@ public:
|
||||||
capi::resize(mWindowWidth, mWindowHeight);
|
capi::resize(mWindowWidth, mWindowHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void SendMediaSessionAction(int32_t action) {
|
void SendMediaSessionAction(capi::CMediaSessionActionType action) {
|
||||||
capi::media_session_action(action);
|
capi::media_session_action(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -272,7 +272,10 @@ hstring ServoControl::LoadURIOrSearch(hstring input) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServoControl::SendMediaSessionAction(int32_t action) {
|
void ServoControl::SendMediaSessionAction(int32_t action) {
|
||||||
RunOnGLThread([=] { mServo->SendMediaSessionAction(action); });
|
RunOnGLThread([=] {
|
||||||
|
mServo->SendMediaSessionAction(
|
||||||
|
static_cast<Servo::MediaSessionActionType>(action));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServoControl::TryLoadUri(hstring input) {
|
void ServoControl::TryLoadUri(hstring input) {
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
#include "OpenGLES.h"
|
#include "OpenGLES.h"
|
||||||
#include "Servo.h"
|
#include "Servo.h"
|
||||||
#include "DefaultUrl.h"
|
#include "DefaultUrl.h"
|
||||||
#include "MediaSession.h"
|
|
||||||
|
|
||||||
namespace winrt::ServoApp::implementation {
|
namespace winrt::ServoApp::implementation {
|
||||||
struct ServoControl : ServoControlT<ServoControl>, public servo::ServoDelegate {
|
struct ServoControl : ServoControlT<ServoControl>, public servo::ServoDelegate {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue