Last active
November 4, 2016 04:48
-
-
Save yoshihiko-ikenaga/e795acd6a2adb924a7237990852026d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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