Skip to content

Commit 86a4e2e

Browse files
authored
Merge pull request #95 from RelistenNet/archive-down-alert
Add alert for audio loading errors
2 parents 7e008e2 + 87e4286 commit 86a4e2e

File tree

6 files changed

+33
-0
lines changed

6 files changed

+33
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"react-timeago": "^8.3.0",
4343
"react-use-cookie": "^1.6.1",
4444
"redux": "^4.2.1",
45+
"sonner": "^2.0.7",
4546
"tailwind-merge": "^3.3.1",
4647
"thenby": "^1.3.4",
4748
"ua-parser-js": "^1.0.37",

pnpm-lock.yaml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/gapless.cjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
onPlayPreviousTrack,
4343
onStartNewTrack,
4444
webAudioIsDisabled = false,
45+
onError,
4546
} = props;
4647

4748
this.props = {
@@ -50,6 +51,7 @@
5051
onPlayNextTrack,
5152
onPlayPreviousTrack,
5253
onStartNewTrack,
54+
onError,
5355
};
5456

5557
this.state = {
@@ -209,6 +211,10 @@
209211

210212
this.tracks.map((track) => track.setVolume(nextVolume));
211213
}
214+
215+
onError() {
216+
if (this.props.onError) this.props.onError();
217+
}
212218
}
213219

214220
class Track {
@@ -485,6 +491,7 @@
485491
// basic event handlers
486492
audioOnError = (e) => {
487493
this.debug('audioOnError', e);
494+
this.queue.onError();
488495
};
489496

490497
onEnded(from) {

src/app/(browse)/layout.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import NavBar from '@/components/NavBar';
33
import cn from '@/lib/cn';
44
import { getIsInIframe } from '@/lib/isInIframe';
55
import { ReactNode } from 'react';
6+
import { Toaster } from 'sonner';
67

78
export default async function BrowseLayout({
89
children,
@@ -23,6 +24,7 @@ export default async function BrowseLayout({
2324

2425
return (
2526
<Flex column className="h-screen">
27+
<Toaster id="audio-error" position="top-center" richColors closeButton />
2628
<NavBar />
2729
<div
2830
className={cn(

src/components/Player.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import player from '../lib/player';
99
import { durationToHHMMSS, removeLeadingZero, splitShowDate } from '../lib/utils';
1010
import Flex from './Flex';
1111
import {
12+
AlertCircle,
1213
ChevronDown,
1314
FastForwardIcon,
1415
ListMusicIcon,
@@ -17,6 +18,7 @@ import {
1718
RewindIcon,
1819
Volume2Icon,
1920
} from 'lucide-react';
21+
import { Toaster } from 'sonner';
2022

2123
interface Props {
2224
artistSlugsToName: Record<string, string | undefined>;

src/lib/player.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { splitShowDate } from './utils';
55
import { scrobblePlay } from '../redux/modules/live';
66
import { updatePlayback } from '../redux/modules/playback';
77
import { ActiveTrack, GaplessMetadata } from '../types';
8+
import { toast } from 'sonner';
89

910
declare global {
1011
interface Window {
@@ -156,6 +157,12 @@ const player = new Gapless.Queue({
156157
}
157158
}
158159
},
160+
onError: () => {
161+
toast.error('There was an error loading your audio', {
162+
toasterId: 'audio-error',
163+
duration: Infinity,
164+
});
165+
},
159166
});
160167

161168
export function initGaplessPlayer(nextStore, changeURL) {

0 commit comments

Comments
 (0)