user2875405
user2875405

Reputation: 45

changing the playing video with on demand script

For some reason my youtube video switcher on my blog won't play the videos once they are changed, and it has something to do with this light youtube embed script http://www.labnol.org/internet/light-youtube-embeds/27941/ I am using to speed up the page loading time. The full example is here http://jsfiddle.net/aw6P9/ Please help I've been googling this all da

HTML:

<div style='text-align:center'>Select a video to watch: <select onChange="playVideo(this)"><option value="v09">Best of the Web - 2013</option><option value="v01">People are Awesome - 2013</option><option value="v08">JP Auclair Street Segment - All.I.Can</option><option value="v07">Natural Phenomena time lapse</option><option value="v06">Welcome, your new Mac - Apple</option><option value="v05">Yosemite Range of Light time lapse</option><option value="v04">Train Yard bike stunts @ TD</option><option value="v03">7 Billion People - Nat. Geo.</option><option value="v02">I love the Whole World - Discovery</option></select><div id='videoPlayback'><div class="videoWrapper"><div class="youtube" id="1-8isxa5B_Y" style="width:671px;height:402px;"></div></div></div>

JS:

<script type='text/javascript'>function playVideo(c){c=document.getElementById(c.value);b=document.getElementById("videoPlayback");b.innerHTML=c.innerHTML};</script><script src='//millerext.googlecode.com/svn/youtube' defer></script>

Upvotes: 0

Views: 254

Answers (1)

brent
brent

Reputation: 924

As you can see to get the on demand videos you have to use a script from an external site which you call via:

<script src='//millerext.googlecode.com/svn/youtube' defer></script>

The problem with this is that that bit of code only runs once when the page loads and therefore won't run again when you change the video over. Therefore to fix that you can just get the code for that script which is here:

http://ctrlq.org/code/19452-embed-youtube-with-javascript

And then insert that code into the script that runs when swapping the video over, ie:

function playVideo(a) {
        a = document.getElementById(a.value);
        b = document.getElementById("videoPlayback");
        b.innerHTML = a.innerHTML;  

        /**ondomandcode**/

I added the code to that jsfiddle you created: http://jsfiddle.net/aw6P9/1/

Upvotes: 0

Related Questions