Skip to content

Instantly share code, notes, and snippets.

@aasumitro
Created September 22, 2023 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aasumitro/84f28f6428f9b0ea79007a04a74c0daa to your computer and use it in GitHub Desktop.
Save aasumitro/84f28f6428f9b0ea79007a04a74c0daa to your computer and use it in GitHub Desktop.
audio detection
<!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