Skip to content

Commit

Permalink
Merge pull request #27 from sunriseL/fix-some-bug
Browse files Browse the repository at this point in the history
Fix two bugs: no sound and crash on some songs
  • Loading branch information
betta-cyber committed Nov 30, 2021
2 parents c3613ac + ccf65a9 commit a921656
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/player/fetch.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io::prelude::*;
use futures::channel::oneshot::Sender;
use reqwest::header::{HOST, CACHE_CONTROL, PRAGMA, HeaderMap, UPGRADE_INSECURE_REQUESTS, ACCEPT, ACCEPT_ENCODING, USER_AGENT};
use reqwest::header::{CACHE_CONTROL, PRAGMA, HeaderMap, UPGRADE_INSECURE_REQUESTS, ACCEPT, ACCEPT_ENCODING, USER_AGENT};
use reqwest::Method;
use tempfile::NamedTempFile;

Expand All @@ -14,7 +14,6 @@ pub async fn fetch_data(url: &str, buffer: NamedTempFile, tx: Sender<String>) ->
headers.insert(CACHE_CONTROL, "no-cache".parse().unwrap());
headers.insert(PRAGMA, "no-cache".parse().unwrap());
headers.insert(UPGRADE_INSECURE_REQUESTS, "1".parse().unwrap());
headers.insert(HOST, "m7.music.126.net".parse().unwrap());
headers.insert(ACCEPT, "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3".parse().unwrap());
headers.insert(ACCEPT_ENCODING, "gzip,deflate".parse().unwrap());
headers.insert(
Expand Down
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 a921656

Please sign in to comment.