Skip to content

Commit

Permalink
fix: audio play bug
Browse files Browse the repository at this point in the history
  • Loading branch information
P-Asta committed May 12, 2024
1 parent b17fb93 commit 3de65bb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ fn discord_status(name: String) {
}
let mut client = client.unwrap();
if name == "" {
client.clear_activity().unwrap_or(());
client.clear_activity().unwrap_or_else(|_| {
client.connect().unwrap_or(());
client.clear_activity().unwrap_or(())
});
} else {
let start = SystemTime::now();
let since_the_epoch = start
Expand All @@ -80,7 +83,17 @@ fn discord_status(name: String) {
.assets(Assets::new().large_image("hedgehog"))
.details(&format!("Listening to {name:?}")),
)
.unwrap_or(());
.unwrap_or_else(|_| {
client.connect().unwrap_or(());
client
.set_activity(
activity::Activity::new()
.timestamps(Timestamps::new().start(since_the_epoch as i64))
.assets(Assets::new().large_image("hedgehog"))
.details(&format!("Listening to {name:?}")),
)
.unwrap_or(())
});
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function App() {

useEffect(() => {
if (status == "play") {
audioContainer.current.play()
if (!decodeURI(audioSource.current.src).startsWith(`https://fback.imnyang.xyz//NY64_Cover/Cover/${playing}.mp3`)) {
let date = Date.now();
navigator.mediaSession.metadata = new MediaMetadata({
Expand Down Expand Up @@ -125,7 +126,6 @@ function App() {
}

return <main>
{/* <title>{playing}</title> */}
<audio id="audioContainer" ref={audioContainer}>
<source id="audioSource" src="" ref={audioSource}/>
<source src="https://fback.imnyang.xyz//NY64_Cover/Cover/Bad Apple.mp3"/>
Expand Down

0 comments on commit 3de65bb

Please sign in to comment.