mirror of
https://github.com/Dangoware/dmp-core.git
synced 2025-04-19 06:52:53 -05:00
cleaned some warnings and updated player trait
This commit is contained in:
parent
c8c00a765b
commit
f79bf8d477
3 changed files with 16 additions and 50 deletions
|
@ -4,29 +4,24 @@
|
|||
|
||||
use crossbeam_channel;
|
||||
use crossbeam_channel::{Receiver, Sender};
|
||||
use listenbrainz::ListenBrainz;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::thread::spawn;
|
||||
|
||||
use crossbeam_channel::unbounded;
|
||||
use std::error::Error;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::music_controller::queue::QueueItem;
|
||||
use crate::music_player::gstreamer::GStreamer;
|
||||
use crate::music_storage::library::{Tag, URI};
|
||||
use crate::music_player::player::Player;
|
||||
use crate::music_storage::library::URI;
|
||||
use crate::{
|
||||
config::config::Config,
|
||||
music_controller::queue::Queue,
|
||||
music_storage::library::{MusicLibrary, Song},
|
||||
config::config::Config, music_controller::queue::Queue, music_storage::library::MusicLibrary,
|
||||
};
|
||||
|
||||
pub struct Controller {
|
||||
pub struct Controller<P: Player> {
|
||||
pub queue: Queue,
|
||||
pub config: Arc<RwLock<Config>>,
|
||||
pub library: MusicLibrary,
|
||||
player_mail: MailMan<PlayerCmd, PlayerRes>,
|
||||
pub player: P,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -69,10 +64,10 @@ enum PlayerRes {
|
|||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
impl Controller {
|
||||
pub fn start<P>(config_path: P) -> Result<Self, Box<dyn Error>>
|
||||
impl<P> Controller<P> {
|
||||
pub fn start<T>(config_path: T) -> Result<Self, Box<dyn Error>>
|
||||
where
|
||||
std::path::PathBuf: std::convert::From<P>,
|
||||
std::path::PathBuf: std::convert::From<T>,
|
||||
{
|
||||
let config_path = PathBuf::from(config_path);
|
||||
|
||||
|
@ -84,26 +79,11 @@ impl Controller {
|
|||
|
||||
let (player_mail, in_thread) = MailMan::<PlayerCmd, PlayerRes>::double();
|
||||
|
||||
spawn(move || {
|
||||
let mut player = GStreamer::new().unwrap();
|
||||
|
||||
while true {
|
||||
match in_thread.recv().unwrap() {
|
||||
PlayerCmd::Test(uri) => {
|
||||
&player.set_volume(0.04);
|
||||
_ = &player.enqueue_next(&uri).unwrap();
|
||||
_ = &player.play();
|
||||
in_thread.send(PlayerRes::Test).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Ok(Controller {
|
||||
queue: Queue::new(),
|
||||
config: config_.clone(),
|
||||
library,
|
||||
player_mail,
|
||||
player: P::new(),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
use chrono::Duration;
|
||||
use thiserror::Error;
|
||||
use gstreamer as gst;
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::music_storage::library::URI;
|
||||
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum PlayerError {
|
||||
#[error("player initialization failed")]
|
||||
|
@ -24,6 +23,7 @@ pub enum PlayerError {
|
|||
}
|
||||
|
||||
pub trait Player {
|
||||
fn new() -> Self;
|
||||
fn source(&self) -> &Option<URI>;
|
||||
|
||||
fn enqueue_next(&mut self, next_track: &URI) -> Result<(), PlayerError>;
|
||||
|
@ -53,5 +53,4 @@ pub trait Player {
|
|||
fn seek_by(&mut self, seek_amount: Duration) -> Result<(), PlayerError>;
|
||||
|
||||
fn seek_to(&mut self, target_pos: Duration) -> Result<(), PlayerError>;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ use crate::config::config::Config;
|
|||
// Various std things
|
||||
use std::collections::BTreeMap;
|
||||
use std::error::Error;
|
||||
use std::io::Write;
|
||||
use std::ops::ControlFlow::{Break, Continue};
|
||||
|
||||
// Files
|
||||
|
@ -14,9 +13,8 @@ use file_format::{FileFormat, Kind};
|
|||
use glib::filename_to_uri;
|
||||
use lofty::{AudioFile, ItemKey, ItemValue, ParseOptions, Probe, TagType, TaggedFileExt};
|
||||
use rcue::parser::parse_from_file;
|
||||
use std::fs::{self, File};
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use tempfile::TempDir;
|
||||
use uuid::Uuid;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
|
@ -144,22 +142,17 @@ pub enum DoNotTrack {
|
|||
Discord,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[derive(Debug, Default, Clone, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[non_exhaustive]
|
||||
pub enum SongType {
|
||||
// TODO: add MORE?! song types
|
||||
#[default]
|
||||
Main,
|
||||
Instrumental,
|
||||
Remix,
|
||||
Custom(String),
|
||||
}
|
||||
|
||||
impl Default for SongType {
|
||||
fn default() -> Self {
|
||||
SongType::Main
|
||||
}
|
||||
}
|
||||
|
||||
/// Stores information about a single song
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
|
||||
pub struct Song {
|
||||
|
@ -1127,18 +1120,12 @@ impl MusicLibrary {
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
path::PathBuf,
|
||||
sync::{Arc, RwLock},
|
||||
thread::sleep,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use tempfile::TempDir;
|
||||
|
||||
use crate::{config::config::Config, music_storage::library::MusicLibrary};
|
||||
|
||||
use super::Song;
|
||||
|
||||
#[test]
|
||||
fn library_init() {
|
||||
let config = Config::read_file(PathBuf::from("test_config/config_test.json")).unwrap();
|
||||
|
|
Loading…
Reference in a new issue