Skip to content

Commit

Permalink
player: fix no sound bug
Browse files Browse the repository at this point in the history
According to doc of rodio, the attached OutputStreamHandles will no
longer work after OutputStream is dropped. So player need to own
OutputStream. And currently there is no way to unstopped a Sink, so we
has no choice but to alloc a new Sink in player->start().
  • Loading branch information
sunriseL committed Nov 25, 2021
1 parent c3613ac commit 75bf455
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/player/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub struct Player {
pub state: PlayerState,
pub current: Option<Track>,
pub sink: rodio::Sink,
pub stream: rodio::OutputStream,
pub stream_handle: rodio::OutputStreamHandle,
}

// player
Expand All @@ -57,7 +59,9 @@ impl Player {
Player {
state: PlayerState::Stopped,
current: None,
sink: sink,
sink,
stream,
stream_handle,
// endpoint: endpoint,
}
}
Expand Down Expand Up @@ -131,7 +135,7 @@ impl Player {
pub fn start(&mut self) {
let vol = self.sink.volume();
self.sink.stop();
// self.sink = rodio::Sink::new(&self.endpoint);
self.sink = rodio::Sink::try_new(&self.stream_handle).unwrap();
self.set_volume(vol);
}

Expand Down

0 comments on commit 75bf455

Please sign in to comment.