Skip to content

Commit

Permalink
Attempt at fixing audio playback on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
martpie committed Dec 2, 2024
1 parent cd595e2 commit 79243dd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
12 changes: 11 additions & 1 deletion src/lib/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,18 @@ class Player {
return this.track;
}

setTrack(track: Track) {
async setTrack(track: Track) {
this.track = track;

// Cursed Linux: https://github.com/tauri-apps/tauri/issues/3725#issuecomment-2325248116
if (window.__MUSEEKS_PLATFORM === 'linux') {
const blobUrl = URL.createObjectURL(
await fetch(convertFileSrc(track.path)).then((res) => res.blob()),
);
this.audio.src = blobUrl;
return;
}

this.audio.src = convertFileSrc(track.path);
}

Expand Down
12 changes: 6 additions & 6 deletions src/stores/usePlayerStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const usePlayerStore = createPlayerStore<PlayerState>((set, get) => ({
if (queuePosition > -1) {
const track = queue[queuePosition];

player.setTrack(track);
await player.setTrack(track);
await player.play().catch(logAndNotifyError);

let queueCursor = queuePosition; // Clean that variable mess later
Expand Down Expand Up @@ -205,7 +205,7 @@ const usePlayerStore = createPlayerStore<PlayerState>((set, get) => ({
const track = queue[newQueueCursor];

if (track !== undefined) {
player.setTrack(track);
await player.setTrack(track);
await player.play();
set({
playerStatus: PlayerStatus.PLAY,
Expand Down Expand Up @@ -237,7 +237,7 @@ const usePlayerStore = createPlayerStore<PlayerState>((set, get) => ({
const newTrack = queue[newQueueCursor];

if (newTrack !== undefined) {
player.setTrack(newTrack);
await player.setTrack(newTrack);
await player.play();

set({
Expand Down Expand Up @@ -374,7 +374,7 @@ const usePlayerStore = createPlayerStore<PlayerState>((set, get) => ({
const { queue } = get();
const track = queue[index];

player.setTrack(track);
await player.setTrack(track);
await player.play();

set({
Expand Down Expand Up @@ -511,7 +511,7 @@ function createPlayerStore<T extends PlayerState>(store: StateCreator<T>) {
};
},
onRehydrateStorage: () => {
return (state, error) => {
return async (state, error) => {
if (error || state == null) {
logAndNotifyError(
error,
Expand All @@ -522,7 +522,7 @@ function createPlayerStore<T extends PlayerState>(store: StateCreator<T>) {
const { queue, queueCursor } = state;
if (queue && queueCursor) {
const track = queue[queueCursor];
player.setTrack(track);
await player.setTrack(track);
}
}
};
Expand Down

0 comments on commit 79243dd

Please sign in to comment.