mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
SpircManager: Update state from player and mixer before sending info
This commit is contained in:
parent
ec0e81f0ae
commit
5ef28bf2a5
1 changed files with 39 additions and 11 deletions
50
src/spirc.rs
50
src/spirc.rs
|
@ -1,6 +1,5 @@
|
||||||
use eventual::Async;
|
use eventual::Async;
|
||||||
use protobuf::{self, Message, RepeatedField};
|
use protobuf::{self, Message, RepeatedField};
|
||||||
use std::borrow::Cow;
|
|
||||||
use std::sync::{mpsc, Mutex, Arc};
|
use std::sync::{mpsc, Mutex, Arc};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
@ -57,6 +56,42 @@ pub struct State {
|
||||||
pub end_of_track: bool,
|
pub end_of_track: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl State {
|
||||||
|
pub fn new() -> State {
|
||||||
|
let state = State {
|
||||||
|
status: PlayStatus::kPlayStatusStop,
|
||||||
|
position_ms: 0,
|
||||||
|
position_measured_at: 0,
|
||||||
|
update_time: 0,
|
||||||
|
volume: 0,
|
||||||
|
track: None,
|
||||||
|
end_of_track: false,
|
||||||
|
};
|
||||||
|
state.update_time()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_from_player(mut self, player: &Player) -> State {
|
||||||
|
let player_state = player.state();
|
||||||
|
let (position_ms, position_measured_at) = player_state.position();
|
||||||
|
self.status = player_state.status();
|
||||||
|
self.position_ms = position_ms;
|
||||||
|
self.position_measured_at = position_measured_at;
|
||||||
|
self.track = player_state.track;
|
||||||
|
self.end_of_track = player_state.end_of_track();
|
||||||
|
self.update_time()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_from_mixer(mut self, mixer: &Box<Mixer + Send>) -> State {
|
||||||
|
self.volume = mixer.volume();
|
||||||
|
self.update_time()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_time(mut self) -> State {
|
||||||
|
self.update_time = util::now_ms();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl SpircManager {
|
impl SpircManager {
|
||||||
pub fn new(session: Session, player: Player, mixer: Box<Mixer + Send>) -> SpircManager {
|
pub fn new(session: Session, player: Player, mixer: Box<Mixer + Send>) -> SpircManager {
|
||||||
let ident = session.device_id().to_owned();
|
let ident = session.device_id().to_owned();
|
||||||
|
@ -432,16 +467,9 @@ impl<'a> CommandSender<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send(self) {
|
fn send(self) {
|
||||||
//TODO: get data
|
let state = State::new()
|
||||||
let state = Cow::Owned(State {
|
.update_from_player(&self.spirc_internal.player)
|
||||||
status: PlayStatus::kPlayStatusStop,
|
.update_from_mixer(&self.spirc_internal.mixer);
|
||||||
position_ms: 0,
|
|
||||||
position_measured_at: 0,
|
|
||||||
update_time: util::now_ms(),
|
|
||||||
volume: 0,
|
|
||||||
track: None,
|
|
||||||
end_of_track: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
let mut pkt = protobuf_init!(protocol::spirc::Frame::new(), {
|
let mut pkt = protobuf_init!(protocol::spirc::Frame::new(), {
|
||||||
version: 1,
|
version: 1,
|
||||||
|
|
Loading…
Reference in a new issue