mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-04-28 06:21:23 +00:00
feat: implemented loop functionality on daemon level
This commit is contained in:
+18
-1
@@ -126,5 +126,22 @@ async fn commands_loop(listener: UnixListener) -> Result<(), Box<dyn Error>> {
|
||||
}
|
||||
|
||||
async fn player_loop() {
|
||||
loop {}
|
||||
loop {
|
||||
let mut audio_player = get_audio_player().await.lock().await;
|
||||
|
||||
// Start playback again if loop is enabled
|
||||
let should_play = audio_player.get_state() == PlayerState::Stopped
|
||||
&& audio_player.current_file_path.is_some()
|
||||
&& audio_player.looped;
|
||||
|
||||
if should_play {
|
||||
let file_path = audio_player.current_file_path.clone().unwrap();
|
||||
audio_player
|
||||
.play(&file_path)
|
||||
.await
|
||||
.expect("Something went wrong while trying to play the file");
|
||||
}
|
||||
|
||||
sleep(Duration::from_millis(100)).await;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@ pub struct AudioPlayer {
|
||||
pub duration: Option<f32>,
|
||||
|
||||
pub current_file_path: Option<PathBuf>,
|
||||
|
||||
pub looped: bool,
|
||||
}
|
||||
|
||||
impl AudioPlayer {
|
||||
@@ -62,6 +64,8 @@ impl AudioPlayer {
|
||||
duration: None,
|
||||
|
||||
current_file_path: None,
|
||||
|
||||
looped: false,
|
||||
};
|
||||
|
||||
if default_input_device.is_some() {
|
||||
@@ -222,7 +226,7 @@ impl AudioPlayer {
|
||||
}
|
||||
|
||||
pub fn get_current_file_path(&mut self) -> &Option<PathBuf> {
|
||||
if self.get_state() == PlayerState::Stopped {
|
||||
if self.get_state() == PlayerState::Stopped && !self.looped {
|
||||
self.current_file_path = None;
|
||||
}
|
||||
&self.current_file_path
|
||||
|
||||
Reference in New Issue
Block a user