views:

35

answers:

1

I'd like to be able to get the src value that is actually used for a video element like the following:

<video>
  <source src="foo.mp4"  type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
  <source src="foo.webm" type='video/webm; codecs="vp8, vorbis"'>
  <source src="foo.ogv"  type='video/ogg; codecs="theora, vorbis"'>
</video>

In Firefox (at least), src is defined for the source elements but not for the video element.

How can I find which source is used?

+2  A: 

I think I've answered my own question: the currentSrc property of the video element.

This works in Firefox, Safari (and Chrome, I assume) on Windows XP SP3, at least.

UPDATE: as was pointed out to me in the comments below, there is documentation of currentSrc in the WHATWG spec.

Sam Dutton
<http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#location-of-the-media-resource>. (It's shared by audio and video.)
Ms2ger
currentSrc is a property of the HTMLMediaElement interface.http://www.whatwg.org/specs/web-apps/current-work/complete.html#dom-media-currentsrc
Lachlan Hunt
Thanks! I looked in the spec and (for some reason) couldn't find it, then Googled for 'currentSrc' and 'video currentSrc' and didn't find anything relevant... I've edited my answer accordingly.
Sam Dutton