Skip to content

Instantly share code, notes, and snippets.

Created November 12, 2014 18:22
Show Gist options
  • Save anonymous/eb8c234380b0f0ecc9de to your computer and use it in GitHub Desktop.
Save anonymous/eb8c234380b0f0ecc9de to your computer and use it in GitHub Desktop.
//media API
//Zalmy simply rocks 111111!!!!
adrma.Media = function() {
if (!this instanceof adrma.Media) {
return new adrma.Media();
}
return this;
};
adrma.Media.prototype = {
defaults: {
container: "",
playerClass: "mediaPlayer",
dimentions: {
width: 400,
height: 400
}
},
init: function(config) {
var self = this;
self.timeStamp = new Date().getTime();
$.extend(self, this.defaults, config);
self.container = $(self.container); // covers string, DOM or jQuery object;
self.playerContainer = $("<div>", {
"class": self.playerClass
});
self.container.append(self.playerContainer);
self.resetObj();
},
resetObj: function() {
this.container.find("." + this.playerClass).html("<object id='" + this.playerClass + "_" + this.timeStamp + "'></object>");
},
play: function(type, id) {
//id can be the video id or the "string resource path"
var self = this,
typeObj = self.types[type];
if (!typeObj) {
return; // throw error
}
this.playerContainer.removeClass("hide");
self.resolveDependencies(typeObj.dependencies).done(function() {
typeObj.load.apply(self, [id]);
});
},
remove: function() {
this.playerContainer.addClass("hide");
this.resetObj();
},
types: {
youTube: {
dependencies: [{
swfobject: "/sup/js/lib/swfobject.js"
}],
load: function(id) {
var url = "https://www.youtube.com/v/" + id + "?version=3&f=user_uploads",
objId = this.playerClass + "_" + this.timeStamp;
params = {
allowScriptAccess: "always",
wmode:"opaque"
},
atts = {
id: objId
};
swfobject.embedSWF(url + "&enablejsapi=1&autoplay=1&theme=light&modestbranding=1&color=white&fs=1&hd=1&autohide=1", objId, this.dimentions.width, this.dimentions.height, "8", null, null, params, atts);
}
},
vimeo: {
dependencies: [{
swfobject: "/sup/js/lib/swfobject.js"
}],
load: function (id) {
var flashvars = {
'clip_id': id,
'server': 'vimeo.com',
'show_title': 0,
'show_byline': 0,
'show_portrait': 0,
'fullscreen': 0,
'autoplay': 1,
'js_api': 1,
'js_onload': 'vimeo_player_loaded'
};
var parObj = {
'swliveconnect': true,
'fullscreen': 1,
'allowscriptaccess': 'always',
'allowfullscreen': true
};
var attObj = {};
swfobject.embedSWF("http://www.vimeo.com/moogaloop.swf", "videoObj", this.dimentions.width, this.dimentions.height, "9.0.28", '', flashvars, parObj, attObj);
}
},
html5: {
dependencies: [{
"adrma.videoPlayer": "/sup/js/videoPlayer.js"
}],
bindAction: function() {
//adrma.videoPlayer.init();
}
}
},
resolveDependencies: function(dependencies) {
var dfd = $.Deferred(),
deferreds = [];
for (var dependency in dependencies) {
if (window.dependency) { // in case of .'ed resource, augument and apply...
continue;
}
deferreds.push(adrma.fetchData({
url: "/sup/js/lib/swfobject.js",
dataType: "script"
}));
}
if (deferreds.length) {
$.when.apply(null, deferreds).done(function() {
dfd.resolve();
});
return dfd;
} else {
return dfd.resolve();
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment