utils.ts
744 Bytes
export enum VideoPlayerType {
m3u8 = 'application/x-mpegURL',
mp4 = 'video/mp4',
webm = 'video/webm',
}
export const getVideoTypeByUrl = (url: string) => {
const splitExtReg = /(?:.*)(?<=\.)/;
const type = url.replace(splitExtReg, '');
/**
* https://vcsplay.scjtonline.cn:8200/live/HD_1569b634-4789-11eb-ab67-3cd2e55e0b20.m3u8?auth_key=1681179278-0-0-5c54a376f2ca32d05c4a152ee96336e9
* 如果是这种格式的m3u8,则截取的是这一部分.m3u8?auth_key=1681179278-0-0-5c54a376f2ca32d05c4a152ee96336e9
*/
if (type.startsWith('m3u8')) return VideoPlayerType.m3u8;
if (type.startsWith('mp4')) return VideoPlayerType.mp4;
if (type.startsWith('webm')) return VideoPlayerType.webm;
return VideoPlayerType.webm;
};