diff --git a/index.html b/index.html
index 93b0f19..b16d67b 100644
--- a/index.html
+++ b/index.html
@@ -929,6 +929,20 @@ async function readAudioInfo(file) {
} catch {}
return info;
}
+async function readDuration(file) {
+ try {
+ const url = URL.createObjectURL(file);
+ const dur = await new Promise((resolve) => {
+ const a = new Audio();
+ a.preload = 'metadata';
+ a.onloadedmetadata = () => { resolve(a.duration); };
+ a.onerror = () => { resolve(0); };
+ a.src = url;
+ });
+ URL.revokeObjectURL(url);
+ return isFinite(dur) && dur > 0 ? dur : 0;
+ } catch { return 0; }
+}
async function processFiles(files, paths) {
scanning.style.display = 'flex';
const total = files.length;
@@ -940,7 +954,7 @@ async function processFiles(files, paths) {
prog++;
const url = URL.createObjectURL(file);
const path = paths ? paths[i] : file.name;
- const [tags, ainfo] = await Promise.all([readTags(file), readAudioInfo(file)]);
+ const [tags, ainfo, duration] = await Promise.all([readTags(file), readAudioInfo(file), readDuration(file)]);
const name = tags.title || file.name.replace(/\.[^.]+$/, '');
found.push({
name,
@@ -958,7 +972,7 @@ async function processFiles(files, paths) {
file,
path,
size: file.size,
- playtime: 0,
+ playtime: duration,
ainfo,
});
scanningText.textContent = `Processing ${prog}: ${name}`;