fix(deprecations): remove dead ScriptProcessorNode PCM code (eliminates console warning); improve YouTube playerVars with origin/modestbranding (reduce postMessage spam); fix Timer stopwatch (now properly counts UP, clean display + interval)
Per PLAN item 7.
This commit is contained in:
@@ -45,6 +45,8 @@ export default function MusicPlayer() {
|
|||||||
loop: 1,
|
loop: 1,
|
||||||
playlist: active.videoId,
|
playlist: active.videoId,
|
||||||
enablejsapi: 1,
|
enablejsapi: 1,
|
||||||
|
origin: window.location.origin,
|
||||||
|
modestbranding: 1,
|
||||||
},
|
},
|
||||||
events: {
|
events: {
|
||||||
onReady: (e: any) => {
|
onReady: (e: any) => {
|
||||||
|
|||||||
@@ -68,6 +68,9 @@ export default function Timer() {
|
|||||||
if (!running) return;
|
if (!running) return;
|
||||||
intervalRef.current = setInterval(() => {
|
intervalRef.current = setInterval(() => {
|
||||||
setRemaining((r) => {
|
setRemaining((r) => {
|
||||||
|
if (mode === 'stopwatch') {
|
||||||
|
return r + 1; // count UP for stopwatch
|
||||||
|
}
|
||||||
if (r <= 1) {
|
if (r <= 1) {
|
||||||
stop();
|
stop();
|
||||||
if (mode === 'pomodoro') setSessions((s) => s + 1);
|
if (mode === 'pomodoro') setSessions((s) => s + 1);
|
||||||
@@ -79,7 +82,7 @@ export default function Timer() {
|
|||||||
return stop;
|
return stop;
|
||||||
}, [running, mode, stop]);
|
}, [running, mode, stop]);
|
||||||
|
|
||||||
const progress = presetMinutes > 0 ? 1 - remaining / (presetMinutes * 60) : 0;
|
const progress = mode === 'stopwatch' ? 0 : (presetMinutes > 0 ? 1 - remaining / (presetMinutes * 60) : 0);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="glass-card p-4">
|
<div className="glass-card p-4">
|
||||||
@@ -112,10 +115,7 @@ export default function Timer() {
|
|||||||
{/* Timer display */}
|
{/* Timer display */}
|
||||||
<div className="text-center py-2">
|
<div className="text-center py-2">
|
||||||
<div className="text-5xl font-extrabold tracking-widest text-kira-plum tabular-nums">
|
<div className="text-5xl font-extrabold tracking-widest text-kira-plum tabular-nums">
|
||||||
{mode === 'stopwatch'
|
{formatTime(remaining)}
|
||||||
? formatTime(Math.floor((presetMinutes * 60 - remaining + presetMinutes * 60) || remaining))
|
|
||||||
: formatTime(remaining)
|
|
||||||
}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Progress bar */}
|
{/* Progress bar */}
|
||||||
|
|||||||
@@ -307,36 +307,4 @@ function arrayBufferToBase64(buffer: ArrayBufferLike): string {
|
|||||||
return btoa(binary);
|
return btoa(binary);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Capture PCM16 mono 24kHz audio from mic and send via callback. */
|
// (Legacy PCM capture removed - MediaRecorder full-blob path is active; eliminates ScriptProcessorNode deprecation)
|
||||||
function startPCMCapture(
|
|
||||||
stream: MediaStream,
|
|
||||||
onChunk: (pcm16: Uint8Array) => void,
|
|
||||||
): { stop: () => void } {
|
|
||||||
const ctx = new AudioContext({ sampleRate: 24000 });
|
|
||||||
const source = ctx.createMediaStreamSource(stream);
|
|
||||||
const processor = ctx.createScriptProcessor(4096, 1, 1);
|
|
||||||
let running = true;
|
|
||||||
|
|
||||||
processor.onaudioprocess = (e) => {
|
|
||||||
if (!running) return;
|
|
||||||
const input = e.inputBuffer.getChannelData(0);
|
|
||||||
const pcm16 = new Int16Array(input.length);
|
|
||||||
for (let i = 0; i < input.length; i++) {
|
|
||||||
const s = Math.max(-1, Math.min(1, input[i]));
|
|
||||||
pcm16[i] = s < 0 ? s * 0x8000 : s * 0x7fff;
|
|
||||||
}
|
|
||||||
onChunk(new Uint8Array(pcm16.buffer));
|
|
||||||
};
|
|
||||||
|
|
||||||
source.connect(processor);
|
|
||||||
processor.connect(ctx.destination);
|
|
||||||
|
|
||||||
return {
|
|
||||||
stop: () => {
|
|
||||||
running = false;
|
|
||||||
source.disconnect();
|
|
||||||
processor.disconnect();
|
|
||||||
ctx.close();
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user