Skip to content

Instantly share code, notes, and snippets.

@yoshihiko-ikenaga
Last active November 4, 2016 04:48
Show Gist options
  • Save yoshihiko-ikenaga/e795acd6a2adb924a7237990852026d4 to your computer and use it in GitHub Desktop.
Save yoshihiko-ikenaga/e795acd6a2adb924a7237990852026d4 to your computer and use it in GitHub Desktop.
validFile(file, success, error) {
const MAX_VIDEO_SIZE = 1024 * 1024 * 100;
const MAX_VIDEO_DURATION = 30;
const SIZE_ERROR = 1;
const DURATION_ERROR = 2;
if (file.size() > MAX_VIDEO_SIZE) {
error(SIZE_ERROR);
return;
}
let video = document.createElement('video');
video.preload = 'metadata';
video.onloadedmetadata = function() {
window.URL.revokeObjectURL(this.src);
let duration = video.duration;
if (duration > MAX_VIDEO_DURATION) {
error(DURATION_ERROR);
return;
}
success(file);
};
video.src = URL.createObjectURL(e.target.files[0]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment