mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Block player thread when nothing is playing.
This commit is contained in:
parent
17d4534260
commit
22d586e473
2 changed files with 15 additions and 9 deletions
|
@ -1,5 +1,5 @@
|
||||||
use byteorder::{BigEndian, ByteOrder, ReadBytesExt, WriteBytesExt};
|
use byteorder::{BigEndian, ByteOrder, ReadBytesExt, WriteBytesExt};
|
||||||
use eventual;
|
use eventual::{self, Async};
|
||||||
use protobuf::{self, Message};
|
use protobuf::{self, Message};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io::{Cursor, Read, Write};
|
use std::io::{Cursor, Read, Write};
|
||||||
|
@ -100,7 +100,7 @@ impl MercuryManager {
|
||||||
uri: uri,
|
uri: uri,
|
||||||
content_type: None,
|
content_type: None,
|
||||||
payload: Vec::new()
|
payload: Vec::new()
|
||||||
});
|
}).fire();
|
||||||
|
|
||||||
rx
|
rx
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,8 +85,14 @@ impl PlayerInternal {
|
||||||
let mut decoder = None;
|
let mut decoder = None;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match self.commands.try_recv() {
|
let cmd = if self.state.0.lock().unwrap().status == PlayStatus::kPlayStatusPlay {
|
||||||
Ok(PlayerCommand::Load(track_id, play, position)) => {
|
self.commands.try_recv().ok()
|
||||||
|
} else {
|
||||||
|
Some(self.commands.recv().unwrap())
|
||||||
|
};
|
||||||
|
|
||||||
|
match cmd {
|
||||||
|
Some(PlayerCommand::Load(track_id, play, position)) => {
|
||||||
self.update(|state| {
|
self.update(|state| {
|
||||||
if state.status == PlayStatus::kPlayStatusPlay {
|
if state.status == PlayStatus::kPlayStatusPlay {
|
||||||
stream.stop().unwrap();
|
stream.stop().unwrap();
|
||||||
|
@ -133,7 +139,7 @@ impl PlayerInternal {
|
||||||
});
|
});
|
||||||
println!("Load Done");
|
println!("Load Done");
|
||||||
}
|
}
|
||||||
Ok(PlayerCommand::Seek(ms)) => {
|
Some(PlayerCommand::Seek(ms)) => {
|
||||||
decoder.as_mut().unwrap().time_seek(ms as f64 / 1000f64).unwrap();
|
decoder.as_mut().unwrap().time_seek(ms as f64 / 1000f64).unwrap();
|
||||||
self.update(|state| {
|
self.update(|state| {
|
||||||
state.position_ms = (decoder.as_mut().unwrap().time_tell().unwrap() * 1000f64) as u32;
|
state.position_ms = (decoder.as_mut().unwrap().time_tell().unwrap() * 1000f64) as u32;
|
||||||
|
@ -141,7 +147,7 @@ impl PlayerInternal {
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
Ok(PlayerCommand::Play) => {
|
Some(PlayerCommand::Play) => {
|
||||||
self.update(|state| {
|
self.update(|state| {
|
||||||
state.status = PlayStatus::kPlayStatusPlay;
|
state.status = PlayStatus::kPlayStatusPlay;
|
||||||
return true;
|
return true;
|
||||||
|
@ -149,7 +155,7 @@ impl PlayerInternal {
|
||||||
|
|
||||||
stream.start().unwrap();
|
stream.start().unwrap();
|
||||||
},
|
},
|
||||||
Ok(PlayerCommand::Pause) => {
|
Some(PlayerCommand::Pause) => {
|
||||||
self.update(|state| {
|
self.update(|state| {
|
||||||
state.status = PlayStatus::kPlayStatusPause;
|
state.status = PlayStatus::kPlayStatusPause;
|
||||||
state.update_time = util::now_ms();
|
state.update_time = util::now_ms();
|
||||||
|
@ -158,7 +164,7 @@ impl PlayerInternal {
|
||||||
|
|
||||||
stream.stop().unwrap();
|
stream.stop().unwrap();
|
||||||
},
|
},
|
||||||
Ok(PlayerCommand::Stop) => {
|
Some(PlayerCommand::Stop) => {
|
||||||
self.update(|state| {
|
self.update(|state| {
|
||||||
if state.status == PlayStatus::kPlayStatusPlay {
|
if state.status == PlayStatus::kPlayStatusPlay {
|
||||||
state.status = PlayStatus::kPlayStatusPause;
|
state.status = PlayStatus::kPlayStatusPause;
|
||||||
|
@ -169,7 +175,7 @@ impl PlayerInternal {
|
||||||
stream.stop().unwrap();
|
stream.stop().unwrap();
|
||||||
decoder = None;
|
decoder = None;
|
||||||
},
|
},
|
||||||
Err(..) => (),
|
None => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.state.0.lock().unwrap().status == PlayStatus::kPlayStatusPlay {
|
if self.state.0.lock().unwrap().status == PlayStatus::kPlayStatusPlay {
|
||||||
|
|
Loading…
Reference in a new issue