Skip to content

Instantly share code, notes, and snippets.

@pietrop
Created February 2, 2021 01:21
Show Gist options
  • Save pietrop/81b1c8e11361d822fbe76f5fd2eb5e7c to your computer and use it in GitHub Desktop.
Save pietrop/81b1c8e11361d822fbe76f5fd2eb5e7c to your computer and use it in GitHub Desktop.
Check the media type using the file extension of a url, works client side
import path from 'path';
const getMediaType = (mediaUrl) => {
const clipExt = path.extname(mediaUrl);
let tmpMediaType = 'video';
if (clipExt === '.wav' || clipExt === '.mp3' || clipExt === '.m4a' || clipExt === '.flac' || clipExt === '.aiff') {
tmpMediaType = 'audio';
}
return tmpMediaType;
};
export default getMediaType;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment