- From: Simon Pieters <simonp@opera.com>
- Date: Fri, 10 Dec 2010 10:45:17 +0100
On Fri, 10 Dec 2010 01:43:27 +0100, Kevin Carle <kcarle at google.com> wrote: >> The use case under discussion is changing to another video. So the >> element >> is already inserted and already has src. >> >> Something like: >> >> <video controls autoplay> >> <source src=video1.webm type=video/webm> >> <source src=video1.mp4 type=video/mp4> >> </video> >> <script> >> function loadVideo(src) { >> var video = document.getElementsByTagName('video')[0]; >> sources = video.getElementsByTagName('source'); >> sources[0].src = src + '.webm'; >> sources[1].src = src + '.mp4'; >> } >> </script> >> <input type="button" value="See video 1" onclick="loadVideo('video1')"> >> <input type="button" value="See video 2" onclick="loadVideo('video2')"> >> <input type="button" value="See video 3" onclick="loadVideo('video3')"> >> >> > Is that really any better than: > > function loadVideo(src) { > var video = document.getElementsByTagName('video')[0]; > if(video.canPlayType("video/webm") != "") { > video.src = src + '.webm'; > } > else { > video.src = src + '.mp4'; > } > } > > -Kevin You'd need to remove the <source> elements to keep the document valid. The author might want to have more than two <source>s, maybe with media="", onerror="" etc. Then it becomes simpler to rely on the resource selection algorithm. -- Simon Pieters Opera Software
Received on Friday, 10 December 2010 01:45:17 UTC