Audio chunk reading
This commit is contained in:
parent
71cc75feff
commit
6b0a53e96f
4 changed files with 22 additions and 3 deletions
|
@ -3,6 +3,7 @@ use image::DynamicImage;
|
||||||
use crate::{ssonic::response::Song, utils::default_cover};
|
use crate::{ssonic::response::Song, utils::default_cover};
|
||||||
|
|
||||||
pub struct Metadata {
|
pub struct Metadata {
|
||||||
|
pub id: String,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub artist: Option<String>,
|
pub artist: Option<String>,
|
||||||
pub playing: bool,
|
pub playing: bool,
|
||||||
|
@ -16,6 +17,7 @@ pub struct Metadata {
|
||||||
impl Metadata {
|
impl Metadata {
|
||||||
pub fn new() -> Metadata {
|
pub fn new() -> Metadata {
|
||||||
Metadata {
|
Metadata {
|
||||||
|
id: String::new(),
|
||||||
name: String::new(),
|
name: String::new(),
|
||||||
artist: None,
|
artist: None,
|
||||||
playing: false,
|
playing: false,
|
||||||
|
@ -32,6 +34,7 @@ impl Metadata {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_metadata(&mut self, song: Song) {
|
pub fn update_metadata(&mut self, song: Song) {
|
||||||
|
self.id = song.id;
|
||||||
self.name = song.title;
|
self.name = song.title;
|
||||||
self.artist = song.artist;
|
self.artist = song.artist;
|
||||||
self.current_time = 0;
|
self.current_time = 0;
|
||||||
|
|
|
@ -21,6 +21,7 @@ pub enum PlayerEvent {
|
||||||
UpdateCover(DynamicImage),
|
UpdateCover(DynamicImage),
|
||||||
UserQuit,
|
UserQuit,
|
||||||
PlayNext,
|
PlayNext,
|
||||||
|
AddAudioChunks(Vec<u8>),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Player {
|
pub struct Player {
|
||||||
|
|
|
@ -80,8 +80,8 @@ impl Player {
|
||||||
self.player_chan_in
|
self.player_chan_in
|
||||||
.send(PlayerEvent::UpdateCover(default_cover()))?;
|
.send(PlayerEvent::UpdateCover(default_cover()))?;
|
||||||
}
|
}
|
||||||
self.fetch_audio_chunk(song.id.clone())?;
|
|
||||||
self.tui_root.metadata.update_metadata(song);
|
self.tui_root.metadata.update_metadata(song);
|
||||||
|
self.fetch_audio_chunk(self.tui_root.metadata.id.clone())?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,22 @@ impl APIClient {
|
||||||
header.insert(RANGE, range_header.parse()?);
|
header.insert(RANGE, range_header.parse()?);
|
||||||
let mut response = self.request("/stream", Some(&[("id", id)]), Some(header))?;
|
let mut response = self.request("/stream", Some(&[("id", id)]), Some(header))?;
|
||||||
|
|
||||||
unimplemented!()
|
if !response.status().is_success() {
|
||||||
|
return Err(Box::new(APIError::StatusError(
|
||||||
|
response.status(),
|
||||||
|
"/stream",
|
||||||
|
)));
|
||||||
|
};
|
||||||
|
|
||||||
|
if response.headers()[CONTENT_TYPE].to_str()? == "application/json" {
|
||||||
|
self.validate(response, "/stream")?; // will never error if not image
|
||||||
|
} else {
|
||||||
|
eprintln!("Fetched chunk");
|
||||||
|
let mut audio_chunk = Vec::new();
|
||||||
|
response.read_to_end(&mut audio_chunk)?;
|
||||||
|
return Ok(PlayerEvent::AddAudioChunks(audio_chunk));
|
||||||
|
}
|
||||||
|
unreachable!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_cover_art(&mut self, cover_id: String) -> Result<PlayerEvent, Error> {
|
fn get_cover_art(&mut self, cover_id: String) -> Result<PlayerEvent, Error> {
|
||||||
|
@ -65,7 +80,7 @@ impl APIClient {
|
||||||
)?;
|
)?;
|
||||||
return Ok(PlayerEvent::UpdateCover(cover));
|
return Ok(PlayerEvent::UpdateCover(cover));
|
||||||
}
|
}
|
||||||
unimplemented!()
|
unreachable!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_random(&mut self, n: i32) -> Result<PlayerEvent, Error> {
|
fn get_random(&mut self, n: i32) -> Result<PlayerEvent, Error> {
|
||||||
|
|
Loading…
Reference in a new issue