mirror of
https://github.com/Dangoware/dango-music-player.git
synced 2025-04-19 10:02:53 -05:00
fixed duration and position values being switched bug
This commit is contained in:
parent
9586c126d0
commit
eab4b41210
2 changed files with 15 additions and 6 deletions
|
@ -34,7 +34,7 @@ impl Controller {
|
||||||
move || {
|
move || {
|
||||||
println!("playback monitor started");
|
println!("playback monitor started");
|
||||||
while true {
|
while true {
|
||||||
let (position, duration) = playback_time_tx.recv().unwrap();
|
let (duration, position) = playback_time_tx.recv().unwrap();
|
||||||
notify_connections
|
notify_connections
|
||||||
.send(ConnectionsNotification::Playback {
|
.send(ConnectionsNotification::Playback {
|
||||||
position: position.clone(),
|
position: position.clone(),
|
||||||
|
|
19
src/App.tsx
19
src/App.tsx
|
@ -288,6 +288,8 @@ function PlayBar({ playing, setPlaying }: PlayBarProps) {
|
||||||
const [seekBarSize, setSeekBarSize] = useState(0);
|
const [seekBarSize, setSeekBarSize] = useState(0);
|
||||||
const seekBarRef = React.createRef<HTMLDivElement>();
|
const seekBarRef = React.createRef<HTMLDivElement>();
|
||||||
|
|
||||||
|
const [lastFmLoggedIn, setLastFmLoggedIn] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const unlisten = appWindow.listen<any>("playback_info", ({ payload, }) => {
|
const unlisten = appWindow.listen<any>("playback_info", ({ payload, }) => {
|
||||||
const info = payload as playbackInfo;
|
const info = payload as playbackInfo;
|
||||||
|
@ -296,7 +298,7 @@ function PlayBar({ playing, setPlaying }: PlayBarProps) {
|
||||||
|
|
||||||
setPosition(pos_);
|
setPosition(pos_);
|
||||||
setDuration(dur_);
|
setDuration(dur_);
|
||||||
let progress = ((dur_/pos_) * 100);
|
let progress = ((pos_/dur_) * 100);
|
||||||
setSeekBarSize(progress)
|
setSeekBarSize(progress)
|
||||||
})
|
})
|
||||||
return () => { unlisten.then((f) => f()) }
|
return () => { unlisten.then((f) => f()) }
|
||||||
|
@ -305,11 +307,17 @@ function PlayBar({ playing, setPlaying }: PlayBarProps) {
|
||||||
const seek = (event: React.MouseEvent<HTMLDivElement>) => {
|
const seek = (event: React.MouseEvent<HTMLDivElement>) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
let rect = seekBarRef.current!.getBoundingClientRect();
|
let rect = seekBarRef.current!.getBoundingClientRect();
|
||||||
let val = ((event.clientX-rect.left) / (rect.width))*position;
|
let val = ((event.clientX-rect.left) / (rect.width))*duration;
|
||||||
|
|
||||||
invoke('seek', { time: Math.round(val * 1000) }).then()
|
invoke('seek', { time: Math.round(val * 1000) }).then()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const lastFmLogin = () => {
|
||||||
|
invoke('last_fm_init_auth').then(() => {
|
||||||
|
setLastFmLoggedIn(true);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section id="playBar" className="playBar unselectable">
|
<section id="playBar" className="playBar unselectable">
|
||||||
<div className="seekBar" ref={ seekBarRef } onClick={ seek } onDrag={ seek }>
|
<div className="seekBar" ref={ seekBarRef } onClick={ seek } onDrag={ seek }>
|
||||||
|
@ -326,16 +334,17 @@ function PlayBar({ playing, setPlaying }: PlayBarProps) {
|
||||||
<button onClick={ () => invoke('next').then(() => {}) }>⏭</button>
|
<button onClick={ () => invoke('next').then(() => {}) }>⏭</button>
|
||||||
</div>
|
</div>
|
||||||
<div className="bottomRight">
|
<div className="bottomRight">
|
||||||
|
<button id="lastFmLogin" onClick={ lastFmLogin } style={{visibility: lastFmLoggedIn ? 'hidden' : 'visible' }} >last.fm</button>
|
||||||
<button>🔀</button>
|
<button>🔀</button>
|
||||||
<button>🔁</button>
|
<button>🔁</button>
|
||||||
<input type="range" name="volume" id="volumeSlider" onChange={ (volume) => {
|
<input type="range" name="volume" id="volumeSlider" onChange={ (volume) => {
|
||||||
invoke('set_volume', { volume: volume.target.value }).then(() => {})
|
invoke('set_volume', { volume: volume.target.value }).then(() => {})
|
||||||
}} />
|
}} />
|
||||||
<p id="timeDisplay">
|
<p id="timeDisplay">
|
||||||
{ Math.floor(+duration / 60).toString().padStart(2, "0") }:
|
|
||||||
{ (+duration % 60).toString().padStart(2, "0") }/
|
|
||||||
{ Math.floor(+position / 60).toString().padStart(2, "0") }:
|
{ Math.floor(+position / 60).toString().padStart(2, "0") }:
|
||||||
{ (+position % 60).toString().padStart(2, "0") }
|
{ (+position % 60).toString().padStart(2, "0") }/
|
||||||
|
{ Math.floor(+duration / 60).toString().padStart(2, "0") }:
|
||||||
|
{ (+duration % 60).toString().padStart(2, "0") }
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue