const getVideoLong = (src: any) => {
return new Promise((res, rej) => {
const v: any = document.createElement("video");
if (typeof src === "string") {
v.src = src;
} else {
v.src = URL.createObjectURL(src);
}
v.autoplay = "autoplay";
v.play();
v.addEventListener("loadedmetadata", () => {
+v.duration && res(v.duration);
!+v.duration && res(null);
});
v.addEventListener("durationchange", () => {
+v.duration && res(v.duration);
!+v.duration && res(null);
});
v.addEventListener("error", () => {
res(null);
});
});
};
export { getVideoLong };
video 通过视频链接地址获取视频时长
最新推荐文章于 2024-06-16 09:46:21 发布