6 Commits
Author SHA1 Message Date
nicknase27 78cb3dc91b test3
Build / build (push) Canceled after 2m36s
2026-08-25 10:25:57 +02:00
nicknase27 64363a12f2 test2
Build / build (push) Canceled after 2m12s
2026-08-25 10:03:41 +02:00
nicknase27 f4138227ab test
Build / build (push) Successful in 2m7s
2026-08-25 09:53:56 +02:00
nicknase27 6fbf09b448 add sample rate support
Build / build (push) Canceled after 23m10s
2026-08-01 18:00:29 +02:00
nicknase27 089f215c42 remove old function from library.rs 2026-07-28 00:11:02 +02:00
nicknase27 b7f08cf6d7 add license 2026-07-27 19:46:17 +02:00
5 changed files with 54 additions and 38 deletions
+9
View File
@@ -0,0 +1,9 @@
The MIT License (MIT)
Copyright © 2026 nicknase27
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View File
+41 -12
View File
@@ -5,14 +5,15 @@ use std::io::BufReader;
use crate::event::{AppEvent, Event, EventHandler};
use crate::library::{Library, Song};
use audiotags::{MimeType, Tag};
use crossterm::event::MediaKeyCode::{self, PlayPause};
use crossterm::event::MediaKeyCode::{self};
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use discord_rich_presence::activity::{Assets, Timestamps};
use discord_rich_presence::{DiscordIpc, DiscordIpcClient, activity};
use ratatui::DefaultTerminal;
use ratatui::widgets::{List, ListItem, ListState};
use rodio::Decoder;
use ratatui::widgets::ListState;
use rodio::{
Decoder, DeviceSinkBuilder, DeviceSinkError, MixerDeviceSink, Player, SampleRate, Source,
};
use std::time::{Duration, SystemTime, UNIX_EPOCH};
#[derive(Debug, Default, PartialEq, Eq)]
@@ -34,8 +35,10 @@ pub struct App {
pub queue: VecDeque<usize>,
pub sink_handle: rodio::MixerDeviceSink,
pub player: rodio::Player,
pub sink_handle: MixerDeviceSink,
pub sample_rate: SampleRate,
pub sink_volume: f32,
pub player: Player,
pub artist_state: ListState,
pub album_state: ListState,
@@ -57,9 +60,9 @@ impl App {
/// Constructs a new instance of [`App`].
pub fn new() -> Self {
let sink_handle =
rodio::DeviceSinkBuilder::open_default_sink().expect("open default audio stream");
let player = rodio::Player::connect_new(sink_handle.mixer());
player.set_volume(1.0);
DeviceSinkBuilder::open_default_sink().expect("open default audio stream");
let player = Player::connect_new(sink_handle.mixer());
// player.set_volume(1.0);
let discord_client = {
let mut client = DiscordIpcClient::new("1525954755292299426");
@@ -76,7 +79,6 @@ impl App {
Self {
running: true,
library: Library::new(),
//songs: get_songs(),
queue: vec![].into(),
artist_state: ListState::default().with_selected(Some(0)),
album_state: ListState::default().with_selected(Some(0)),
@@ -89,6 +91,8 @@ impl App {
paused_at: 1,
sink_handle,
player,
sink_volume: 1.0,
sample_rate: SampleRate::new(44100).unwrap(),
discord_client,
}
}
@@ -252,7 +256,8 @@ impl App {
if vol >= 1.0 {
self.player.set_volume(1.0);
} else {
self.player.set_volume(vol + 0.05);
self.sink_volume = vol + 0.05;
self.player.set_volume(self.sink_volume);
}
}
@@ -261,7 +266,8 @@ impl App {
if vol <= 0.01 {
self.player.set_volume(0.0);
} else {
self.player.set_volume(vol - 0.05);
self.sink_volume = vol - 0.05;
self.player.set_volume(self.sink_volume);
}
}
@@ -425,6 +431,13 @@ impl App {
File::open(&self.library.songs[*self.queue.front().expect("Queue is empty")].path)
.unwrap();
let source = Decoder::new(BufReader::new(file)).unwrap();
let rate: SampleRate = source.sample_rate();
if rate != self.sample_rate {
self.sample_rate = rate;
let _ = self.rebuild_sink(self.sample_rate);
}
self.player.append(source);
self.current_song = Some(self.queue.front().unwrap().to_owned());
self.update_rpc(self.queue.front().unwrap().to_owned());
@@ -444,6 +457,22 @@ impl App {
}
}
pub fn rebuild_sink(&mut self, rate: SampleRate) -> Result<(), DeviceSinkError> {
self.sink_handle.log_on_drop(false);
let mut sink = DeviceSinkBuilder::from_default_device()
.unwrap()
.with_sample_rate(rate)
.open_stream()
.unwrap();
sink.log_on_drop(false);
self.sink_handle = sink;
self.player = Player::connect_new(self.sink_handle.mixer());
self.player.set_volume(self.sink_volume);
Ok(())
}
/// Set running to false to quit the application.
pub fn quit(&mut self) {
self.running = false;
-23
View File
@@ -147,29 +147,6 @@ impl Library {
}
}
/*
fn get_songs() -> Vec<PathBuf> {
let mut songs: Vec<PathBuf> = vec![];
let flacs = WalkDir::new("/mnt/media/music")
.into_iter()
.filter_map(Result::ok)
.filter(|e| {
e.file_type().is_file() && e.path().extension().is_some_and(|ext| ext == "flac")
})
.map(|e| e.into_path());
for path in flacs {
// `path` is a PathBuf
//println!("{}", path.display());
songs.push(path);
}
songs.sort();
songs
}
*/
fn get_songs(library: &Path) -> Vec<PathBuf> {
let mut songs: Vec<PathBuf> = WalkDir::new(library)
.into_iter()
+3 -2
View File
@@ -50,8 +50,9 @@ impl Widget for &mut App {
let now_playing_block = Block::bordered()
.title(format!(
"Now Playing | Vol: {:.0}",
self.player.volume() * 100.0
"Now Playing | Vol: {:.0} | Rate: {}Hz",
self.player.volume() * 100.0,
self.sample_rate
))
.border_type(Rounded);
let inner = now_playing_block.inner(center_area[1]);