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