mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Removed volume struct
This commit is contained in:
parent
fa5c9f7d11
commit
fd1f049572
5 changed files with 4 additions and 41 deletions
|
@ -21,7 +21,6 @@ use librespot_core::spotify_id::{SpotifyAudioType, SpotifyId, SpotifyIdError};
|
|||
use librespot_core::util::url_encode;
|
||||
use librespot_core::util::SeqGenerator;
|
||||
use librespot_core::version;
|
||||
use librespot_core::volume::Volume;
|
||||
|
||||
enum SpircPlayStatus {
|
||||
Stopped,
|
||||
|
@ -1297,7 +1296,7 @@ impl SpircTask {
|
|||
self.mixer
|
||||
.set_volume(volume_to_mixer(volume, &self.config.volume_ctrl));
|
||||
if let Some(cache) = self.session.cache() {
|
||||
cache.save_volume(Volume { volume })
|
||||
cache.save_volume(volume)
|
||||
}
|
||||
self.player.emit_volume_set_event(volume);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ use std::path::{Path, PathBuf};
|
|||
|
||||
use crate::authentication::Credentials;
|
||||
use crate::spotify_id::FileId;
|
||||
use crate::volume::Volume;
|
||||
|
||||
/// A cache for volume, credentials and audio files.
|
||||
#[derive(Clone)]
|
||||
|
@ -80,7 +79,7 @@ impl Cache {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn volume(&self) -> Option<Volume> {
|
||||
pub fn volume(&self) -> Option<u16> {
|
||||
let location = self.volume_location.as_ref()?;
|
||||
|
||||
let read = || {
|
||||
|
@ -103,7 +102,7 @@ impl Cache {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn save_volume(&self, volume: Volume) {
|
||||
pub fn save_volume(&self, volume: u16) {
|
||||
if let Some(ref location) = self.volume_location {
|
||||
let result = File::create(location).and_then(|mut file| write!(file, "{}", volume));
|
||||
if let Err(e) = result {
|
||||
|
|
|
@ -54,4 +54,3 @@ pub mod session;
|
|||
pub mod spotify_id;
|
||||
pub mod util;
|
||||
pub mod version;
|
||||
pub mod volume;
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
use std::fs::File;
|
||||
use std::io::{Read, Write};
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Volume {
|
||||
pub volume: u16,
|
||||
}
|
||||
|
||||
impl Volume {
|
||||
// read volume from file
|
||||
fn from_reader<R: Read>(mut reader: R) -> u16 {
|
||||
let mut contents = String::new();
|
||||
reader.read_to_string(&mut contents).unwrap();
|
||||
contents.trim().parse::<u16>().unwrap()
|
||||
}
|
||||
|
||||
pub(crate) fn from_file<P: AsRef<Path>>(path: P) -> Option<u16> {
|
||||
File::open(path).ok().map(Volume::from_reader)
|
||||
}
|
||||
|
||||
// write volume to file
|
||||
fn save_to_writer<W: Write>(&self, writer: &mut W) {
|
||||
writer
|
||||
.write_all(self.volume.to_string().as_bytes())
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
pub(crate) fn save_to_file<P: AsRef<Path>>(&self, path: P) {
|
||||
let mut file = File::create(path).unwrap();
|
||||
self.save_to_writer(&mut file)
|
||||
}
|
||||
}
|
|
@ -292,9 +292,8 @@ fn setup(args: &[String]) -> Setup {
|
|||
}
|
||||
(volume as i32 * 0xFFFF / 100) as u16
|
||||
})
|
||||
.map(Volume)
|
||||
.or_else(|| cache.as_ref().and_then(Cache::volume))
|
||||
.unwrap_or(Volume(0x8000));
|
||||
.unwrap_or(0x8000);
|
||||
|
||||
let zeroconf_port = matches
|
||||
.opt_str("zeroconf-port")
|
||||
|
|
Loading…
Reference in a new issue