My original post - I couldn't get it working in firefox or IE.
The code from the URL I posted works but I have come up against a roadblock with IE.
Basically, what I am doing is removing then recreating the Video element and Objects etc. when a list item is clicked.
Here is the code:
- Code: Select all
function swapVideos(videoString){
// Remove Old Video
var x = document.getElementById('vid');
document.getElementById('video').removeChild(x);
// Create Elements for New Video
var v = document.createElement('video');
var mp4 = document.createElement('source');
var webm = document.createElement('source');
var ogv = document.createElement('source');
//Flash video elements
var f = document.createElement('object');
var p1 = document.createElement('param');
var p2 = document.createElement('param');
var p3 = document.createElement('param');
var em = document.createElement('embed');
// Populate New Elements
v.setAttribute('id','vid'); v.setAttribute('width','539'); v.setAttribute('height','432'); v.setAttribute('controls',true);
mp4.setAttribute('id','mp4'); mp4.setAttribute('src','video/' + videoString + '.mp4'); mp4.setAttribute('type','video/mp4; codecs="avc1.42E01E, mp4a.40.2"');
webm.setAttribute('id','webm'); webm.setAttribute('src','video/' + videoString + '.webm'); webm.setAttribute('type','video/webm; codecs="vp8, vorbis"');
ogv.setAttribute('id','ogv'); ogv.setAttribute('src','video/' + videoString + '.ogg'); ogv.setAttribute('type','video/ogg; codecs="theora, vorbis"');
//set Flash attributes
f.setAttribute('id','player1'); f.setAttribute('classid','clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'); f.setAttribute('width','539'); f.setAttribute('height','462');
p1.setAttribute('name','movie'); p1.setAttribute('value','video/flashVideoPlayer.swf');
p2.setAttribute('name','allowscriptaccess'); p2.setAttribute('value','always');
p3.setAttribute('name','flashvars'); p3.setAttribute('value','video=' + videoString);
em.setAttribute('id','player1'); em.setAttribute('width','539'); em.setAttribute('height','462'); em.setAttribute('src','video/flashVideoPlayer.swf'); em.setAttribute('flashvars','video=' + videoString); em.setAttribute('allowscriptaccess','always');
// Append New Elements
f.appendChild(p1); f.appendChild(p2); f.appendChild(p3); f.appendChild(em);
v.appendChild(mp4); v.appendChild(webm); v.appendChild(ogv); v.appendChild(f);
document.getElementById('video').appendChild(v);
return true;
}
In IE7 - I am receiving an invalid arguement error.
As IE (up to version 9 anyway), will default to the Flash player I have been focusing on that with the error but I think it may have something to do with IE not liking appendChild();
Any ideas?
Thanks