How do I detect which video source is playing with html5 video
I'm setting up analytics on our html5 videos. Since Chrome, Firefox, etc. currently play different file types (but may change in the future), is there a way with Javascript to get the video source that's actually being played by the brows开发者_运维问答er?
Markup:
<video class="myclass">
<source src="myvid.mp4" type="video/mp4; codecs="avc1.42E01E, mp4a.40.2" />
<source src="myvid.webm" type="video/webm; codecs="vp8, vorbis" />
<source src="myvid.ogv" type="video/ogg; codecs="theora, vorbis" />
</video>
This is not exemplary coding style, but this works for me and should be enough to get you started:
<video class="myclass" onloadeddata="document.getElementById('source').innerHTML
= 'Playing file ' + this.currentSrc">
<source src="myvid.mp4" type="video/mp4; codecs="avc1.42E01E, mp4a.40.2" />
<source src="myvid.webm" type="video/webm; codecs="vp8, vorbis" />
<source src="myvid.ogv" type="video/ogg; codecs="theora, vorbis" />
</video>
<div id="source"></div>
Basically, you want the currentSrc
property after the metadata has been loaded.
I know this ticket is closed but I add another more official solution :
Just do like this:
$(".myclass")[0].currentSrc
Source: http://www.w3schools.com/tags/av_prop_currentsrc.asp
精彩评论