Auto merge of #24885 - shnmorimoto:implement_mediasession_set_positon_state, r=ferjm

Implement mediasession set positon state

<!-- Please describe your changes on the following line: -->

fix #24808

> Bonus points if you want to tweak the existing UI by adding a progress bar, and the info about the current position and total duration.

I haven't implemented this yet.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #24808 (GitHub issue number if applicable)

<!-- Either: -->
- [x] There are tests for these changes OR

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
bors-servo 2019-12-03 12:13:06 -05:00 committed by GitHub
commit f31a88d85d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 183 additions and 34 deletions

View file

@ -132,8 +132,10 @@ pub trait HostTrait {
fn set_clipboard_contents(&self, contents: String);
/// Called when we get the media session metadata/
fn on_media_session_metadata(&self, title: String, artist: String, album: String);
/// Called when the media sessoin playback state changes.
/// Called when the media session playback state changes.
fn on_media_session_playback_state_change(&self, state: i32);
/// Called when the media session position state is set.
fn on_media_session_set_position_state(&self, duration: f64, position: f64, playback_rate: f64);
}
pub struct ServoGlue {
@ -594,6 +596,14 @@ impl ServoGlue {
.callbacks
.host_callbacks
.on_media_session_playback_state_change(state as i32),
MediaSessionEvent::SetPositionState(position_state) => self
.callbacks
.host_callbacks
.on_media_session_set_position_state(
position_state.duration,
position_state.position,
position_state.playback_rate,
),
};
},
EmbedderMsg::Status(..) |

View file

@ -219,6 +219,8 @@ pub struct CHostCallbacks {
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),
pub on_media_session_set_position_state:
extern "C" fn(duration: f64, position: f64, playback_rate: f64),
}
/// Servo options
@ -648,7 +650,7 @@ impl HostTrait for HostCallbacks {
}
fn on_load_started(&self) {
debug!("on_load_ended");
debug!("on_load_started");
(self.0.on_load_started)();
}
@ -727,4 +729,17 @@ impl HostTrait for HostCallbacks {
debug!("on_media_session_playback_state_change {:?}", state);
(self.0.on_media_session_playback_state_change)(state);
}
fn on_media_session_set_position_state(
&self,
duration: f64,
position: f64,
playback_rate: f64,
) {
debug!(
"on_media_session_set_position_state ({:?} {:?} {:?})",
duration, position, playback_rate
);
(self.0.on_media_session_set_position_state)(duration, position, playback_rate);
}
}

View file

@ -560,6 +560,30 @@ impl HostTrait for HostCallbacks {
)
.unwrap();
}
fn on_media_session_set_position_state(
&self,
duration: f64,
position: f64,
playback_rate: f64,
) {
info!(
"on_media_session_playback_state_change ({:?}, {:?}, {:?})",
duration, position, playback_rate
);
let env = self.jvm.get_env().unwrap();
let duration = JValue::Float(duration as jfloat);
let position = JValue::Float(position as jfloat);
let playback_rate = JValue::Float(playback_rate as jfloat);
env.call_method(
self.callbacks.as_obj(),
"onMediaSessionSetPositionState",
"(FFF)V",
&[duration, position, playback_rate],
)
.unwrap();
}
}
fn initialize_android_glue(env: &JNIEnv, activity: JObject) {