File size: 1,953 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
// 计算百分比*总时间(元数据)
export function percentToSeconds(percent: number, time_seconds: number) {
const currentTime = percent * time_seconds;
return currentTime;
}
// 将以 (秒) 显示的格式 -> 以 (分:秒) 显示
export function secondsToMinutesAndSecondes(time_seconds: number) {
const m = Math.floor(time_seconds / 60);
const s = Math.floor(time_seconds % 60);
const minutes = m.toString().length > 1 ? m.toString() : '0' + m.toString();
const seconds = s.toString().length > 1 ? s.toString() : '0' + s.toString();
return minutes + ':' + seconds;
}
// 计算百分比*总时间并以 (分:秒) 显示
export function percentToMinutesAndSeconds(percent: number, time_seconds: number) {
const currentTime = percent * time_seconds;
const m = Math.floor(currentTime / 60);
const s = Math.floor(currentTime % 60);
const minutes = m.toString().length > 1 ? m.toString() : '0' + m.toString();
const seconds = s.toString().length > 1 ? s.toString() : '0' + s.toString();
return minutes + ':' + seconds;
}
export const createALabel = (path: string, fileName: string = 'JoL-player.png') => {
let link = document.createElement('a');
link.style.display = 'none';
link.href = path;
link.setAttribute('download', fileName);
document.body.appendChild(link);
link.click();
link.remove();
window.URL.revokeObjectURL(path);
};
export const capture = (video: HTMLVideoElement, scaleFactor: number = 0.25) => {
var w = video.videoWidth * scaleFactor;
var h = video.videoHeight * scaleFactor;
var canvas = document.createElement('canvas') as HTMLCanvasElement;
canvas.width = w;
canvas.height = h;
var ctx = canvas.getContext('2d');
ctx!.drawImage(video, 0, 0, w, h);
return canvas;
};
export const filterDefaults = (val: unknown) => {
if (val === null || val === undefined) {
return true;
} else if (val === true) {
return true;
} else {
return false;
}
};
|