Skip to content
Permalink
Browse files

Fix libsimpleservo build after MediaSession C enums change

  • Loading branch information
ferjm committed Dec 2, 2019
1 parent b01e3fd commit 58623a6f5bd45f1e0e3f94fca15ab4a3793eb933
@@ -134,7 +134,7 @@ pub trait HostTrait {
/// Called when we get the media session metadata/
fn on_media_session_metadata(&self, title: String, artist: String, album: String);
/// Called when the media session playback state changes.
fn on_media_session_playback_state_change(&self, state: MediaSessionPlaybackState);
fn on_media_session_playback_state_change(&self, state: MediaSessionPlaybackState);
/// Called when the media session position state is set.
fn on_media_session_set_position_state(&self, duration: f64, position: f64, playback_rate: f64);
}
@@ -219,7 +219,7 @@ pub struct CHostCallbacks {
pub set_clipboard_contents: extern "C" fn(contents: *const c_char),
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: CMediaSessionPlaybackState),
pub on_media_session_playback_state_change: extern "C" fn(state: CMediaSessionPlaybackState),
pub on_media_session_set_position_state:
extern "C" fn(duration: f64, position: f64, playback_rate: f64),
}
@@ -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, MediaSessionPlaybackState, VRInitOptions,
};
use std::os::raw::{c_char, c_int, c_void};
use std::ptr::{null, null_mut};
use std::sync::Arc;
@@ -340,7 +342,7 @@ pub fn Java_org_mozilla_servoview_JNIServo_mediaSessionAction(
action: jint,
) {
debug!("mediaSessionAction");
call(&env, |s| s.media_session_action(action as i32));
call(&env, |s| s.media_session_action((action as i32).into()));
}

pub struct WakeupCallback {
@@ -548,9 +550,10 @@ impl HostTrait for HostCallbacks {
.unwrap();
}

fn on_media_session_playback_state_change(&self, state: i32) {
fn on_media_session_playback_state_change(&self, state: MediaSessionPlaybackState) {
info!("on_media_session_playback_state_change {:?}", state);
let env = self.jvm.get_env().unwrap();
let state = state as i32;
let state = JValue::Int(state as jint);
env.call_method(
self.callbacks.as_obj(),
@@ -74,17 +74,19 @@ void BrowserPage::BindServoEvents() {
[=](hstring title, hstring artist, hstring album) {});
servoControl().OnMediaSessionPlaybackStateChange(
[=](const auto &, int state) {
if (state == servo::PlaybackState::NONE) {
if (state == servo::Servo::MediaSessionPlaybackState::None) {
mediaControls().Visibility(Visibility::Collapsed);
return;
}
mediaControls().Visibility(Visibility::Visible);
playButton().Visibility(state == servo::PlaybackState::PAUSED
? Visibility::Visible
: Visibility::Collapsed);
pauseButton().Visibility(state == servo::PlaybackState::PAUSED
? Visibility::Collapsed
: Visibility::Visible);
playButton().Visibility(
state == servo::Servo::MediaSessionPlaybackState::Paused
? Visibility::Visible
: Visibility::Collapsed);
pauseButton().Visibility(
state == servo::Servo::MediaSessionPlaybackState::Paused
? Visibility::Collapsed
: Visibility::Visible);
});
}

@@ -163,13 +165,13 @@ void BrowserPage::OnMediaControlsPlayClicked(
Windows::Foundation::IInspectable const &,
Windows::UI::Xaml::RoutedEventArgs const &) {
servoControl().SendMediaSessionAction(
static_cast<int32_t>(servo::MediaSessionAction::PLAY));
static_cast<int32_t>(servo::Servo::MediaSessionActionType::Play));
}
void BrowserPage::OnMediaControlsPauseClicked(
Windows::Foundation::IInspectable const &,
Windows::UI::Xaml::RoutedEventArgs const &) {
servoControl().SendMediaSessionAction(
static_cast<int32_t>(servo::MediaSessionAction::PAUSE));
static_cast<int32_t>(servo::Servo::MediaSessionActionType::Pause));
}

} // namespace winrt::ServoApp::implementation

0 comments on commit 58623a6

Please sign in to comment.
You can’t perform that action at this time.