Skip to content

Instantly share code, notes, and snippets.

@ashrewdmint
Created November 16, 2010 19:44
Show Gist options
  • Save ashrewdmint/702371 to your computer and use it in GitHub Desktop.
Save ashrewdmint/702371 to your computer and use it in GitHub Desktop.
function viddlerVideoSwitch(objectElement, newId) {
viddlerVideoInterface(objectElement, function(movie){
movie.setMovie(videoId, true);
}, function(video){
video = $(video);
var src = video.attr('src');
var poster = video.attr('poster');
var oldId = src.match(/file\/([^\/]+)\/html5/)[1];
var oldIdRegexp = new RegExp(oldId);
video.attr('src', src.replace(oldIdRegexp, newId));
video.attr('poster', poster.replace(oldIdRegexp, newId));
video.load();
});
}
function viddlerVideoInterface(element, flashCallback, videoCallback) {
var object = element.is('object') ? element : element.find('object');
var embed = element.is('embed') ? element : element.find('embed');
embed = embed.get(0);
var deepObject = object.find('object');
var video = element.find('video');
var flashInterface = embed ? embed : object.get(0);
var triedThat = false;
while (typeof(flashInterface.setMovie) != 'function') {
if (! triedThat) {
flashInterface = object.find('object').get(0);
triedThat = true;
} else {
if (typeof(videoCallback) == 'function' && video.length) {
videoCallback(video.get(0));
}
return;
}
}
if (typeof(flashCallback) == 'function') {
flashCallback(flashInterface);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment