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