Note that there are some explanatory texts on larger screens.

plurals
  1. POchanging source on html5 video tag
    primarykey
    data
    text
    <p>i'm trying to build a video player, that works everywhere. so far i'd be going with:</p> <pre><code>&lt;video&gt; &lt;source src="video.mp4"&gt;&lt;/source&gt; &lt;source src="video.ogv"&gt;&lt;/source&gt; &lt;object data="flowplayer.swf" type="application/x-shockwave-flash"&gt; &lt;param name="movie" value="flowplayer.swf" /&gt; &lt;param name="flashvars" value='config={"clip":"video.mp4"}' /&gt; &lt;/object&gt; &lt;/video&gt; </code></pre> <p>(as seen on several sites, for example <a href="http://camendesign.com/code/video_for_everybody" rel="noreferrer">video for everybody</a>) so far, so good.</p> <p>but now i also want some kind of playlist/menu along with the video player, from which i can select other videos. those should be opened within my player right away. so i will have to "dynamically change the source of the video" (as seen on <a href="http://dev.opera.com/articles/view/everything-you-need-to-know-about-html5-video-and-audio/" rel="noreferrer">dev.opera.com/articles/everything-you-need-to-know-html5-video-audio/</a> - section "Let's look at another movie") with javascript. let's forget about the flashplayer (and thus IE) part for the time being, i will try to deal with that later.</p> <p>so my JS to change the <code>&lt;source&gt;</code> tags should be something like:</p> <pre><code>&lt;script&gt; function loadAnotherVideo() { var video = document.getElementsByTagName('video')[0]; var sources = video.getElementsByTagName('source'); sources[0].src = 'video2.mp4'; sources[1].src = 'video2.ogv'; video.load(); } &lt;/script&gt; </code></pre> <p>problem is, this doesnt work in all browsers. namely, firefox =O there is a nice page, where you can observe the problem i'm having: <a href="http://www.w3.org/2010/05/video/mediaevents.html" rel="noreferrer">http://www.w3.org/2010/05/video/mediaevents.html</a></p> <p>as soon as i trigger the load() method (in firefox, mind you), the video player dies.</p> <p>now i have found out that when i don't use multiple <code>&lt;source&gt;</code> tags, but instead just one src attribute within the <code>&lt;video&gt;</code> tag, the whole thing DOES work in firefox.</p> <p>so my plan is to just use that src attribute and determine the appropriate file using the <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#dom-navigator-canplaytype" rel="noreferrer">canPlayType()</a> function.</p> <p>am i doing it wrong somehow or complicating things??</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload