I am creating a custom controller for MP4 video on a web page. The controller includes a volume slider. Some of the videos that are to be played have no sound track. It would be
There might be a better way of doing this, although it's fairly simple just using regular javascript
for webkit
or mozilla
enabled browsers. webkit
utilizes this.audioTracks
and mozilla
uses this.mozHasAudio
respectively:
document.getElementById("video").addEventListener("loadeddata", function() {
if ('WebkitAppearance' in document.documentElement.style)
var hasAudioTrack = this.audioTracks.length;
else if (this.mozHasAudio)
var hasAudioTrack = 1;
if (hasAudioTrack > 0)
alert("audio track detected");
else
alert("audio track not detected");
});
<video id="video" width="320" height="240" controls>
<source src="http://media.w3.org/2010/05/video/movie_300.mp4" type="video/mp4">
</video>
There's also a function this.webkitAudioDecodedByteCount
, however, I've never had any luck making it work.