Spaces:
Running
Running
File size: 537 Bytes
94004a2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | export function formatTime(s) {
const m = Math.floor(s / 60);
const sec = (s % 60).toFixed(1);
return `${m}:${sec.padStart(4, '0')}`;
}
export async function probeAudioDuration(file) {
return new Promise((resolve) => {
const url = URL.createObjectURL(file);
const a = new Audio();
const done = (v) => { URL.revokeObjectURL(url); resolve(v); };
a.addEventListener('loadedmetadata', () => done(isFinite(a.duration) ? a.duration : null));
a.addEventListener('error', () => done(null));
a.src = url;
});
}
|