Added stop, various small tweaks

This commit is contained in:
G2-Games 2024-12-29 23:15:01 -06:00
parent 077eae00c5
commit 2130af1e4a
6 changed files with 53 additions and 43 deletions

View file

@ -84,6 +84,7 @@ pub enum PlayerCommand {
PrevSong, PrevSong,
Pause, Pause,
Play, Play,
Stop,
Seek(i64), Seek(i64),
Enqueue(usize), Enqueue(usize),
SetVolume(f32), SetVolume(f32),
@ -351,6 +352,11 @@ impl Controller {
player_mail.send(PlayerResponse::Empty(Ok(()))).await.unwrap(); player_mail.send(PlayerResponse::Empty(Ok(()))).await.unwrap();
} }
PlayerCommand::Stop => {
player.write().unwrap().stop();
player_mail.send(PlayerResponse::Empty(Ok(()))).await.unwrap();
}
PlayerCommand::Seek(time) => { PlayerCommand::Seek(time) => {
let res = player.write().unwrap().seek_to(TimeDelta::milliseconds(time)); let res = player.write().unwrap().seek_to(TimeDelta::milliseconds(time));
player_mail.send(PlayerResponse::Empty(res.map_err(|e| e.into()))).await.unwrap(); player_mail.send(PlayerResponse::Empty(res.map_err(|e| e.into()))).await.unwrap();

View file

@ -106,6 +106,14 @@ impl ControllerHandle {
res res
} }
pub async fn stop(&self) -> Result<(), PlayerError> {
self.player_mail.send(PlayerCommand::Stop).await.unwrap();
let PlayerResponse::Empty(res) = self.player_mail.recv().await.unwrap() else {
unreachable!()
};
res
}
pub async fn seek(&self, time: i64) -> Result<(), PlayerError> { pub async fn seek(&self, time: i64) -> Result<(), PlayerError> {
self.player_mail.send(PlayerCommand::Seek(time)).await.unwrap(); self.player_mail.send(PlayerCommand::Seek(time)).await.unwrap();
let PlayerResponse::Empty(res) = self.player_mail.recv().await.unwrap() else { let PlayerResponse::Empty(res) = self.player_mail.recv().await.unwrap() else {

View file

@ -6,11 +6,11 @@ use crossbeam::channel::{bounded, unbounded, Receiver, Sender};
use discord_presence::{models::{Activity, ActivityButton, ActivityTimestamps, ActivityType}, Event}; use discord_presence::{models::{Activity, ActivityButton, ActivityTimestamps, ActivityType}, Event};
use dmp_core::{config::{Config, ConfigLibrary}, music_controller::controller::{Controller, ControllerHandle, LibraryResponse, PlaybackInfo}, music_storage::library::{MusicLibrary, Song}}; use dmp_core::{config::{Config, ConfigLibrary}, music_controller::controller::{Controller, ControllerHandle, LibraryResponse, PlaybackInfo}, music_storage::library::{MusicLibrary, Song}};
use futures::channel::oneshot; use futures::channel::oneshot;
use parking_lot::lock_api::{RawRwLock, RwLock}; use parking_lot::RwLock;
use rfd::FileHandle; use rfd::FileHandle;
use tauri::{http::Response, Emitter, Manager, State, WebviewWindowBuilder, Wry}; use tauri::{http::Response, Emitter, Manager, State, WebviewWindowBuilder, Wry};
use uuid::Uuid; use uuid::Uuid;
use wrappers::_Song; use wrappers::{_Song, stop};
use crate::wrappers::{get_library, play, pause, prev, set_volume, get_song, next, get_queue, import_playlist, get_playlist, get_playlists, remove_from_queue, seek}; use crate::wrappers::{get_library, play, pause, prev, set_volume, get_song, next, get_queue, import_playlist, get_playlist, get_playlists, remove_from_queue, seek};
use commands::{add_song_to_queue, play_now, display_album_art}; use commands::{add_song_to_queue, play_now, display_album_art};
@ -97,6 +97,7 @@ pub fn run() {
get_library, get_library,
play, play,
pause, pause,
stop,
set_volume, set_volume,
next, next,
prev, prev,
@ -123,7 +124,7 @@ pub fn run() {
.name("PlaybackInfo handler".to_string()) .name("PlaybackInfo handler".to_string())
.spawn(move || { .spawn(move || {
let mut _info = Arc::new(RwLock::new(PlaybackInfo::default())); let mut _info = Arc::new(RwLock::new(PlaybackInfo::default()));
let mut _now_playing: Arc<RwLock<_, Option<Song>>> = Arc::new(RwLock::new(None)); let mut _now_playing = Arc::new(RwLock::new(None));
scope(|s| { scope(|s| {
let info = _info.clone(); let info = _info.clone();
@ -153,36 +154,6 @@ pub fn run() {
let info = _info.clone(); let info = _info.clone();
let now_playing = _now_playing.clone(); let now_playing = _now_playing.clone();
s.spawn(|| {
let info = info;
let now_playing = now_playing;
let mut rpc_client = discord_presence::Client::new(std::env!("DISCORD_SECRET").parse::<u64>().unwrap());
rpc_client.start();
rpc_client.block_until_event(Event::Connected).unwrap();
rpc_client.set_activity(|_| {
Activity {
state: Some("Idle".to_string()),
_type: Some(ActivityType::Listening),
buttons: vec![ActivityButton {
label: Some("Try the Player!(beta)".to_string()),
url: Some("https://github.com/Dangoware/dango-music-player".to_string())
}],
..Default::default()
}
}).unwrap();
while true {
rpc_client.set_activity(|mut a| {
if let Some(song) = now_playing.read().clone() {
a.timestamps = info.read().duration.map(|dur| ActivityTimestamps::new().end(dur.num_milliseconds() as u64) );
a.details = Some(format!("{} 🍡 {}" song.tags. ))
}
a
});
}
});
}); });
}).unwrap(); }).unwrap();
@ -228,7 +199,7 @@ pub fn run() {
.run(|_app_handle, event| match event { .run(|_app_handle, event| match event {
tauri::RunEvent::ExitRequested { api, .. } => { tauri::RunEvent::ExitRequested { api, .. } => {
// api.prevent_exit(); // api.prevent_exit();
panic!("does this kill the player?") //panic!("does this kill the player?")
} }
_ => {} _ => {}
}); });

View file

@ -2,7 +2,7 @@ use std::{collections::BTreeMap, path::PathBuf};
use chrono::{DateTime, Utc, serde::ts_milliseconds_option}; use chrono::{DateTime, Utc, serde::ts_milliseconds_option};
use crossbeam::channel::Sender; use crossbeam::channel::Sender;
use dmp_core::{music_controller::controller::{ControllerHandle, LibraryCommand, LibraryResponse, PlayerLocation, PlayerResponse, QueueCommand, QueueResponse}, music_storage::library::{Song, Tag, URI}}; use dmp_core::{music_controller::controller::{ControllerHandle, PlayerLocation}, music_storage::library::{Song, Tag, URI}};
use itertools::Itertools; use itertools::Itertools;
use kushi::QueueItemType; use kushi::QueueItemType;
use serde::Serialize; use serde::Serialize;
@ -31,7 +31,17 @@ pub async fn pause(app: AppHandle<Wry>, ctrl_handle: State<'_, ControllerHandle>
} }
Err(e) => Err(e.to_string()) Err(e) => Err(e.to_string())
} }
}
#[tauri::command]
pub async fn stop(app: AppHandle<Wry>, ctrl_handle: State<'_, ControllerHandle>) -> Result<(), String> {
match ctrl_handle.stop().await {
Ok(()) => {
app.emit("stop", ()).unwrap();
Ok(())
}
Err(e) => Err(e.to_string())
}
} }
#[tauri::command] #[tauri::command]

View file

@ -52,6 +52,7 @@ main {
/* Change to resize width */ /* Change to resize width */
width: 350px; width: 350px;
min-width: 350px;
} }
.bottom { .bottom {
@ -137,6 +138,9 @@ main {
.bottomRight { .bottomRight {
display: flex; display: flex;
justify-content: space-around; justify-content: space-around;
align-items: center;
color: var(--highlightTextColor);
margin-top: 14px;
} }
button { button {
@ -146,14 +150,25 @@ main {
width: 50px; width: 50px;
height: 100%; height: 100%;
margin-right: 15px; margin-right: 15px;
color: #FFF; color: var(--mediumTextColor);
cursor: pointer;
} }
} }
.playBar button:hover {
color: var(--highlightTextColor);
}
#seekBar { #seekBar {
width: 100%; width: 100%;
} }
#timeDisplay {
font-family: monospace;
font-size: 14px;
margin: 0 20px;
}
.nowPlaying { .nowPlaying {
font-size: 14pt; font-size: 14pt;
width: 100%; width: 100%;
@ -243,4 +258,5 @@ main {
.unselectable { .unselectable {
-webkit-user-select: none; -webkit-user-select: none;
user-select: none; user-select: none;
cursor: default;
} }

View file

@ -304,8 +304,7 @@ function PlayBar({ playing, setPlaying }: PlayBarProps) {
setPosition(_pos); setPosition(_pos);
setDuration(_dur); setDuration(_dur);
let progress = (Math.floor((_pos/_dur)*100)); let progress = ((_pos/_dur) * 100);
console.log(progress + '%');
setSeekBarSize(progress) setSeekBarSize(progress)
}) })
return () => { unlisten.then((f) => f()) } return () => { unlisten.then((f) => f()) }
@ -341,9 +340,9 @@ function PlayBar({ playing, setPlaying }: PlayBarProps) {
invoke('set_volume', { volume: volume.target.value }).then(() => {}) invoke('set_volume', { volume: volume.target.value }).then(() => {})
}} /> }} />
<p id="timeDisplay"> <p id="timeDisplay">
{ Math.round(+position / 60) }: { Math.round(+position / 60).toString().padStart(2, "0") }:
{ (+position % 60).toString().padStart(2, "0") }/ { (+position % 60).toString().padStart(2, "0") }/
{ Math.round(+duration / 60) }: { Math.round(+duration / 60).toString().padStart(2, "0") }:
{ (+duration % 60).toString().padStart(2, "0") } { (+duration % 60).toString().padStart(2, "0") }
</p> </p>
</div> </div>