mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-07 04:20:12 +02:00
fix radio cancellation error on double click (#1419)
This commit is contained in:
Vendored
+1
-1
@@ -6,8 +6,8 @@ declare global {
|
||||
interface Window {
|
||||
api: PreloadApi;
|
||||
electron: ElectronAPI;
|
||||
queryLocalFonts?: () => Promise<Font[]>;
|
||||
LEGACY_AUTHENTICATION?: boolean;
|
||||
queryLocalFonts?: () => Promise<Font[]>;
|
||||
SERVER_LOCK?: boolean;
|
||||
SERVER_NAME?: string;
|
||||
SERVER_TYPE?: ServerType;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import console from 'console';
|
||||
import IcecastMetadataStats from 'icecast-metadata-stats';
|
||||
import isElectron from 'is-electron';
|
||||
import { useEffect, useRef } from 'react';
|
||||
@@ -134,6 +135,7 @@ export const useRadioAudioInstance = () => {
|
||||
const volume = usePlayerVolume();
|
||||
const isMuted = usePlayerMuted();
|
||||
const audioRef = useRef<HTMLAudioElement | null>(null);
|
||||
const activeAudioRef = useRef<HTMLAudioElement | null>(null);
|
||||
const isUsingMpv = playbackType === PlayerType.LOCAL && mpvPlayer;
|
||||
|
||||
// Handle mpv playback
|
||||
@@ -205,6 +207,7 @@ export const useRadioAudioInstance = () => {
|
||||
|
||||
const audio = new Audio(currentStreamUrl);
|
||||
audioRef.current = audio;
|
||||
activeAudioRef.current = audio;
|
||||
|
||||
const linearVolume = volume / 100;
|
||||
const logVolume = convertToLogVolume(linearVolume);
|
||||
@@ -231,6 +234,10 @@ export const useRadioAudioInstance = () => {
|
||||
|
||||
// Attempt to play
|
||||
audio.play().catch((error) => {
|
||||
if (activeAudioRef.current !== audio) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.error('Failed to play audio:', error);
|
||||
setIsPlaying(false);
|
||||
setCurrentStreamUrl(null);
|
||||
@@ -243,10 +250,14 @@ export const useRadioAudioInstance = () => {
|
||||
audioRef.current.src = '';
|
||||
audioRef.current = null;
|
||||
}
|
||||
activeAudioRef.current = null;
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (audioRef.current) {
|
||||
if (activeAudioRef.current === audioRef.current) {
|
||||
activeAudioRef.current = null;
|
||||
}
|
||||
audioRef.current.pause();
|
||||
audioRef.current.src = '';
|
||||
audioRef.current = null;
|
||||
|
||||
Reference in New Issue
Block a user