mirror of
https://github.com/Dangoware/dango-music-player.git
synced 2025-04-19 10:02:53 -05:00
Added stop, various small tweaks
This commit is contained in:
parent
077eae00c5
commit
2130af1e4a
6 changed files with 53 additions and 43 deletions
|
@ -84,6 +84,7 @@ pub enum PlayerCommand {
|
|||
PrevSong,
|
||||
Pause,
|
||||
Play,
|
||||
Stop,
|
||||
Seek(i64),
|
||||
Enqueue(usize),
|
||||
SetVolume(f32),
|
||||
|
@ -351,6 +352,11 @@ impl Controller {
|
|||
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) => {
|
||||
let res = player.write().unwrap().seek_to(TimeDelta::milliseconds(time));
|
||||
player_mail.send(PlayerResponse::Empty(res.map_err(|e| e.into()))).await.unwrap();
|
||||
|
|
|
@ -106,6 +106,14 @@ impl ControllerHandle {
|
|||
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> {
|
||||
self.player_mail.send(PlayerCommand::Seek(time)).await.unwrap();
|
||||
let PlayerResponse::Empty(res) = self.player_mail.recv().await.unwrap() else {
|
||||
|
|
|
@ -6,11 +6,11 @@ use crossbeam::channel::{bounded, unbounded, Receiver, Sender};
|
|||
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 futures::channel::oneshot;
|
||||
use parking_lot::lock_api::{RawRwLock, RwLock};
|
||||
use parking_lot::RwLock;
|
||||
use rfd::FileHandle;
|
||||
use tauri::{http::Response, Emitter, Manager, State, WebviewWindowBuilder, Wry};
|
||||
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 commands::{add_song_to_queue, play_now, display_album_art};
|
||||
|
@ -97,6 +97,7 @@ pub fn run() {
|
|||
get_library,
|
||||
play,
|
||||
pause,
|
||||
stop,
|
||||
set_volume,
|
||||
next,
|
||||
prev,
|
||||
|
@ -123,7 +124,7 @@ pub fn run() {
|
|||
.name("PlaybackInfo handler".to_string())
|
||||
.spawn(move || {
|
||||
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| {
|
||||
let info = _info.clone();
|
||||
|
@ -153,36 +154,6 @@ pub fn run() {
|
|||
|
||||
let info = _info.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();
|
||||
|
@ -228,7 +199,7 @@ pub fn run() {
|
|||
.run(|_app_handle, event| match event {
|
||||
tauri::RunEvent::ExitRequested { api, .. } => {
|
||||
// api.prevent_exit();
|
||||
panic!("does this kill the player?")
|
||||
//panic!("does this kill the player?")
|
||||
}
|
||||
_ => {}
|
||||
});
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::{collections::BTreeMap, path::PathBuf};
|
|||
|
||||
use chrono::{DateTime, Utc, serde::ts_milliseconds_option};
|
||||
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 kushi::QueueItemType;
|
||||
use serde::Serialize;
|
||||
|
@ -31,7 +31,17 @@ pub async fn pause(app: AppHandle<Wry>, ctrl_handle: State<'_, ControllerHandle>
|
|||
}
|
||||
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]
|
||||
|
|
18
src/App.css
18
src/App.css
|
@ -52,6 +52,7 @@ main {
|
|||
|
||||
/* Change to resize width */
|
||||
width: 350px;
|
||||
min-width: 350px;
|
||||
}
|
||||
|
||||
.bottom {
|
||||
|
@ -137,6 +138,9 @@ main {
|
|||
.bottomRight {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
align-items: center;
|
||||
color: var(--highlightTextColor);
|
||||
margin-top: 14px;
|
||||
}
|
||||
|
||||
button {
|
||||
|
@ -146,14 +150,25 @@ main {
|
|||
width: 50px;
|
||||
height: 100%;
|
||||
margin-right: 15px;
|
||||
color: #FFF;
|
||||
color: var(--mediumTextColor);
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
.playBar button:hover {
|
||||
color: var(--highlightTextColor);
|
||||
}
|
||||
|
||||
#seekBar {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#timeDisplay {
|
||||
font-family: monospace;
|
||||
font-size: 14px;
|
||||
margin: 0 20px;
|
||||
}
|
||||
|
||||
.nowPlaying {
|
||||
font-size: 14pt;
|
||||
width: 100%;
|
||||
|
@ -243,4 +258,5 @@ main {
|
|||
.unselectable {
|
||||
-webkit-user-select: none;
|
||||
user-select: none;
|
||||
cursor: default;
|
||||
}
|
11
src/App.tsx
11
src/App.tsx
|
@ -304,8 +304,7 @@ function PlayBar({ playing, setPlaying }: PlayBarProps) {
|
|||
|
||||
setPosition(_pos);
|
||||
setDuration(_dur);
|
||||
let progress = (Math.floor((_pos/_dur)*100));
|
||||
console.log(progress + '%');
|
||||
let progress = ((_pos/_dur) * 100);
|
||||
setSeekBarSize(progress)
|
||||
})
|
||||
return () => { unlisten.then((f) => f()) }
|
||||
|
@ -341,10 +340,10 @@ function PlayBar({ playing, setPlaying }: PlayBarProps) {
|
|||
invoke('set_volume', { volume: volume.target.value }).then(() => {})
|
||||
}} />
|
||||
<p id="timeDisplay">
|
||||
{ Math.round(+position / 60) }:
|
||||
{ (+position % 60).toString().padStart(2, "0") } /
|
||||
{ Math.round(+duration / 60) }:
|
||||
{ (+duration % 60).toString().padStart(2, "0") }
|
||||
{ Math.round(+position / 60).toString().padStart(2, "0") }:
|
||||
{ (+position % 60).toString().padStart(2, "0") }/
|
||||
{ Math.round(+duration / 60).toString().padStart(2, "0") }:
|
||||
{ (+duration % 60).toString().padStart(2, "0") }
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue