Fix: Skip-Button startet jetzt beim nächsten Segment + Initialisierung für Specials

- autoPlay verwendet jetzt startPos statt startTime beim Skip
- hasPlayedOnce wird nur bei Song-Wechsel zurückgesetzt, nicht bei mehr Zeit
- processedSrc/processedUnlockedSeconds initial auf null für korrekte Initialisierung
- Sicherstellt, dass Specials weiterhin vom markierten Ausschnitt starten
This commit is contained in:
Hördle Bot
2026-01-24 12:42:26 +01:00
parent cebdf7a5a2
commit 096682929d

View File

@@ -22,8 +22,8 @@ const AudioPlayer = forwardRef<AudioPlayerRef, AudioPlayerProps>(({ src, unlocke
const [progress, setProgress] = useState(0); const [progress, setProgress] = useState(0);
const [hasPlayedOnce, setHasPlayedOnce] = useState(false); const [hasPlayedOnce, setHasPlayedOnce] = useState(false);
const [processedSrc, setProcessedSrc] = useState(src); const [processedSrc, setProcessedSrc] = useState<string | null>(null);
const [processedUnlockedSeconds, setProcessedUnlockedSeconds] = useState(unlockedSeconds); const [processedUnlockedSeconds, setProcessedUnlockedSeconds] = useState<number | null>(null);
useEffect(() => { useEffect(() => {
console.log('[AudioPlayer] MOUNTED'); console.log('[AudioPlayer] MOUNTED');
@@ -41,7 +41,7 @@ const AudioPlayer = forwardRef<AudioPlayerRef, AudioPlayerProps>(({ src, unlocke
let startPos = startTime; let startPos = startTime;
// If same song but more time unlocked, start from where previous segment ended // If same song but more time unlocked, start from where previous segment ended
if (src === processedSrc && unlockedSeconds > processedUnlockedSeconds) { if (processedSrc !== null && src === processedSrc && processedUnlockedSeconds !== null && unlockedSeconds > processedUnlockedSeconds) {
startPos = startTime + processedUnlockedSeconds; startPos = startTime + processedUnlockedSeconds;
} }
@@ -62,8 +62,11 @@ const AudioPlayer = forwardRef<AudioPlayerRef, AudioPlayerProps>(({ src, unlocke
const initialPercent = unlockedSeconds > 0 ? (initialElapsed / unlockedSeconds) * 100 : 0; const initialPercent = unlockedSeconds > 0 ? (initialElapsed / unlockedSeconds) * 100 : 0;
setProgress(Math.min(initialPercent, 100)); setProgress(Math.min(initialPercent, 100));
setHasPlayedOnce(false); // Reset for new segment // Only reset hasPlayedOnce if the song changed, not if just more time was unlocked
if (processedSrc !== null && src !== processedSrc) {
setHasPlayedOnce(false); // Reset for new song
onHasPlayedChange?.(false); // Notify parent onHasPlayedChange?.(false); // Notify parent
}
// Update processed state // Update processed state
setProcessedSrc(src); setProcessedSrc(src);
@@ -73,8 +76,9 @@ const AudioPlayer = forwardRef<AudioPlayerRef, AudioPlayerProps>(({ src, unlocke
// Delay play slightly to ensure currentTime sticks // Delay play slightly to ensure currentTime sticks
setTimeout(() => { setTimeout(() => {
if (audioRef.current) { if (audioRef.current) {
// Ensure currentTime is set before playing // Use startPos (which may be startTime + processedUnlockedSeconds if more time was unlocked)
audioRef.current.currentTime = startTime; // instead of always using startTime
audioRef.current.currentTime = startPos;
const playPromise = audioRef.current.play(); const playPromise = audioRef.current.play();
if (playPromise !== undefined) { if (playPromise !== undefined) {
playPromise playPromise