mpris
This commit is contained in:
parent
636a73a27f
commit
2476557ec3
2 changed files with 30 additions and 2 deletions
|
|
@ -232,6 +232,7 @@ pub struct MprisState {
|
|||
position_micros: i64,
|
||||
paused: bool,
|
||||
volume: f64,
|
||||
will_repeat: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
@ -742,10 +743,15 @@ impl App {
|
|||
position_micros: (self.position * 1_000_000.0) as i64,
|
||||
paused: true,
|
||||
volume: 0.0,
|
||||
will_repeat: false,
|
||||
};
|
||||
if let Some(video) = &self.video_opt {
|
||||
new.paused = video.paused();
|
||||
new.volume = video.volume();
|
||||
|
||||
let repeat_state = &self.flags.config_state.player_state.repeat;
|
||||
new.will_repeat = *repeat_state == RepeatState::Always
|
||||
|| (*repeat_state == RepeatState::Once && !self.has_media_repeated);
|
||||
}
|
||||
if new != *old {
|
||||
*old = new.clone();
|
||||
|
|
|
|||
26
src/mpris.rs
26
src/mpris.rs
|
|
@ -10,7 +10,7 @@ use mpris_server::{
|
|||
use std::{any::TypeId, future, process};
|
||||
use tokio::sync::{Mutex, mpsc};
|
||||
|
||||
use crate::{Message, MprisEvent, MprisMeta, MprisState};
|
||||
use crate::{Message, MprisEvent, MprisMeta, MprisState, config::RepeatState};
|
||||
|
||||
impl MprisMeta {
|
||||
fn metadata(&self) -> Metadata {
|
||||
|
|
@ -58,6 +58,16 @@ impl MprisState {
|
|||
PlaybackStatus::Playing
|
||||
}
|
||||
}
|
||||
|
||||
fn loop_status(&self) -> LoopStatus {
|
||||
if self.will_repeat {
|
||||
// TODO: Our choice is between Track and Playlist. Track is the best match for current repeat behavior,
|
||||
// but this may change when we implement mpris playlists.
|
||||
LoopStatus::Track
|
||||
} else {
|
||||
LoopStatus::None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Player {
|
||||
|
|
@ -194,11 +204,19 @@ impl PlayerInterface for Player {
|
|||
|
||||
async fn loop_status(&self) -> fdo::Result<LoopStatus> {
|
||||
log::info!("LoopStatus");
|
||||
Ok(LoopStatus::None)
|
||||
let state = self.state.lock().await;
|
||||
Ok(state.loop_status())
|
||||
}
|
||||
|
||||
async fn set_loop_status(&self, loop_status: LoopStatus) -> Result<()> {
|
||||
log::info!("SetLoopStatus({})", loop_status);
|
||||
let repeat_state = if loop_status == LoopStatus::None {
|
||||
RepeatState::Disabled
|
||||
} else {
|
||||
// TODO: This may change when we implement mpris playlists.
|
||||
RepeatState::Always
|
||||
};
|
||||
self.message(Message::RepeatToggled(repeat_state)).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -418,6 +436,10 @@ pub fn subscription() -> Subscription<Message> {
|
|||
position: Time::from_micros(new.position_micros),
|
||||
});
|
||||
}
|
||||
let new_loop_status = new.loop_status();
|
||||
if new_loop_status != old.loop_status() {
|
||||
props.push(Property::LoopStatus(new_loop_status));
|
||||
}
|
||||
*old = new;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue