Created
July 28, 2013 17:40
-
-
Save dharFr/6099405 to your computer and use it in GitHub Desktop.
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="A Simple Video Instant Preview Demo" /> | |
<meta charset=utf-8 /> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<video id="video" controls></video> | |
<form> | |
<label for="filein"> Choose a video file to preview : | |
<input id="filein" type="file"/> | |
</label> | |
</form> | |
<div id="output"></div> | |
</body> | |
</html> |
This file contains 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
(function videoPreview() | |
{ | |
var video, filein, output, blobUrl; | |
video = document.getElementById('video'); | |
filein = document.getElementById('filein'); | |
ouput = document.getElementById('output'); | |
function setOutput(txt) { ouput.textContent = txt; } | |
function clearOutput() { setOutput(''); } | |
if (!window.URL || !window.URL.createObjectURL || !filein.files) | |
{ | |
setOutput("File API isn't supported..."); | |
return; | |
} | |
filein.addEventListener('change', function onChange(e) | |
{ | |
var chosenFile = filein.files[0]; | |
// clear current blob if it's already set | |
if (blobUrl) | |
{ | |
window.URL.revokeObjectURL(blobUrl); | |
} | |
// Check if the browser can play selected file | |
if (video.canPlayType(chosenFile.type)) | |
{ | |
clearOutput(); | |
blobUrl = window.URL.createObjectURL(chosenFile); | |
video.src = blobUrl; | |
} | |
else | |
{ | |
setOutput("Your browser can't read " + chosenFile.type + " files."); | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment