Skip to content

Commit 16a54b3

Browse files
committed
Audio: catch low-level errors
1 parent 8373c1c commit 16a54b3

File tree

4 files changed

+6
-3
lines changed

4 files changed

+6
-3
lines changed

src/apps/call/Telephone.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export function Telephone(props: {
127127

128128
// pickup / hangup
129129
React.useEffect(() => {
130-
!isRinging && AudioPlayer.playUrl(isConnected ? '/sounds/chat-begin.mp3' : '/sounds/chat-end.mp3');
130+
!isRinging && void AudioPlayer.playUrl(isConnected ? '/sounds/chat-begin.mp3' : '/sounds/chat-end.mp3').catch(() => {/* autoplay may be blocked */});
131131
}, [isRinging, isConnected]);
132132

133133
// ringtone

src/apps/call/state/usePlayUrlInterval.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export function usePlayUrlInterval(url: string | null, firstDelay: number = 0, r
1717
let timer2: any = null;
1818

1919
const playFirstTime = () => {
20-
const playAudio = () => AudioPlayer.playUrl(url, abortController.signal);
21-
void playAudio();
20+
const playAudio = () => void AudioPlayer.playUrl(url, abortController.signal).catch(() => {/* autoplay may be blocked */});
21+
playAudio();
2222
timer2 = repeatMs > 0 ? setInterval(playAudio, repeatMs) : null;
2323
};
2424

src/common/util/audio/AudioPlayer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ export namespace AudioPlayer {
33
/**
44
* Plays an audio file from a URL. Resolves when playback ends.
55
* If a signal is provided and aborted, playback stops and the promise resolves.
6+
*
7+
* @throws If there's an error during playback (e.g. network error, unsupported format), the promise will reject.
68
*/
79
export function playUrl(url: string, signal?: AbortSignal): Promise<void> {
810
if (signal?.aborted || !url) return Promise.resolve();

src/modules/aix/client/aix.client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@ async function _aixChatGenerateContent_LL(
721721
(audio) => {
722722
const audioUrl = URL.createObjectURL(audio.blob);
723723
void AudioPlayer.playUrl(audioUrl)
724+
.catch(error => console.log('[AIX] Failed to play audio:', { error }))
724725
.finally(() => URL.revokeObjectURL(audioUrl));
725726
},
726727
);

0 commit comments

Comments
 (0)