add player controller

This commit is contained in:
Yanzhen Yu
2026-04-01 12:00:00 +08:00
parent b4e983af89
commit edadb57eb4
5 changed files with 206 additions and 59 deletions

33
src/utils.js Normal file
View File

@@ -0,0 +1,33 @@
export function inlineCss(cssObj) {
let style = '';
Object.keys(cssObj).forEach(key => {
style += `${key}: ${cssObj[key]};`;
});
return style;
}
function padZero(num, len = 2) {
const threshold = Math.pow(10, len - 1);
if (num < threshold) {
num = String(num);
while (String(threshold).length > num.length) {
num = '0' + num;
}
}
return num;
}
const SECOND = 1000;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
export function formatTime(ms) {
const hour = Math.floor(ms / HOUR);
ms = ms % HOUR;
const minute = Math.floor(ms / MINUTE);
ms = ms % MINUTE;
const second = Math.floor(ms / SECOND);
if (hour) {
return `${padZero(hour)}:${padZero(minute)}:${padZero(minute)}`;
}
return `${padZero(hour)}:${padZero(second)}`;
}