Created
September 22, 2023 07:23
-
-
Save aasumitro/84f28f6428f9b0ea79007a04a74c0daa to your computer and use it in GitHub Desktop.
audio detection
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Video Audio Detection</title> | |
</head> | |
<body> | |
<input type="file" id="videoInput" accept="video/*"> | |
<video id="videoElement" width="320" height="240" controls autoplay style="display: none"></video> | |
<script> | |
document.getElementById('videoInput').addEventListener('change', function(e) { | |
var file = e.target.files[0]; | |
document.getElementById('videoElement').src = URL.createObjectURL(file); | |
}, false); | |
document.getElementById("videoElement").addEventListener("loadeddata", function() { | |
if (typeof this.webkitAudioDecodedByteCount !== "undefined") { | |
if (this.webkitAudioDecodedByteCount > 0) | |
alert("This video has audio"); | |
else | |
alert("no audio"); | |
} else if (typeof this.mozHasAudio !== "undefined") { | |
if (this.mozHasAudio) | |
alert("This video has audio"); | |
else | |
alert("no audio"); | |
} else if (typeof this.audioTracks !== "undefined") { | |
if (this.audioTracks && this.audioTracks.length) | |
alert("audible"); | |
else | |
alert("not audible"); | |
} else | |
alert("Not sure"); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment