Skip to content

Commit

Permalink
Merge pull request mediaelement#1079 from clkao/vimeo-support
Browse files Browse the repository at this point in the history
Vimeo support
  • Loading branch information
johndyer committed Mar 27, 2014
2 parents 5711f6a + 7a5c08b commit ab9aa89
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 23 deletions.
14 changes: 7 additions & 7 deletions src/js/me-mediaelements.js
Expand Up @@ -97,7 +97,7 @@ mejs.PluginMediaElement.prototype = {
// HTML5 methods
play: function () {
if (this.pluginApi != null) {
if (this.pluginType == 'youtube') {
if (this.pluginType == 'youtube' || this.pluginType == 'vimeo') {
this.pluginApi.playVideo();
} else {
this.pluginApi.playMedia();
Expand All @@ -107,7 +107,7 @@ mejs.PluginMediaElement.prototype = {
},
load: function () {
if (this.pluginApi != null) {
if (this.pluginType == 'youtube') {
if (this.pluginType == 'youtube' || this.pluginType == 'vimeo') {
} else {
this.pluginApi.loadMedia();
}
Expand All @@ -117,7 +117,7 @@ mejs.PluginMediaElement.prototype = {
},
pause: function () {
if (this.pluginApi != null) {
if (this.pluginType == 'youtube') {
if (this.pluginType == 'youtube' || this.pluginType == 'vimeo') {
this.pluginApi.pauseVideo();
} else {
this.pluginApi.pauseMedia();
Expand All @@ -129,7 +129,7 @@ mejs.PluginMediaElement.prototype = {
},
stop: function () {
if (this.pluginApi != null) {
if (this.pluginType == 'youtube') {
if (this.pluginType == 'youtube' || this.pluginType == 'vimeo') {
this.pluginApi.stopVideo();
} else {
this.pluginApi.stopMedia();
Expand Down Expand Up @@ -199,7 +199,7 @@ mejs.PluginMediaElement.prototype = {
},
setCurrentTime: function (time) {
if (this.pluginApi != null) {
if (this.pluginType == 'youtube') {
if (this.pluginType == 'youtube' || this.pluginType == 'vimeo') {
this.pluginApi.seekTo(time);
} else {
this.pluginApi.setCurrentTime(time);
Expand All @@ -213,7 +213,7 @@ mejs.PluginMediaElement.prototype = {
setVolume: function (volume) {
if (this.pluginApi != null) {
// same on YouTube and MEjs
if (this.pluginType == 'youtube') {
if (this.pluginType == 'youtube' || this.pluginType == 'vimeo') {
this.pluginApi.setVolume(volume * 100);
} else {
this.pluginApi.setVolume(volume);
Expand All @@ -223,7 +223,7 @@ mejs.PluginMediaElement.prototype = {
},
setMuted: function (muted) {
if (this.pluginApi != null) {
if (this.pluginType == 'youtube') {
if (this.pluginType == 'youtube' || this.pluginType == 'vimeo') {
if (muted) {
this.pluginApi.mute();
} else {
Expand Down
66 changes: 50 additions & 16 deletions src/js/me-shim.js
Expand Up @@ -603,23 +603,57 @@ mejs.HtmlMediaElementShim = {

// DEMO Code. Does NOT work.
case 'vimeo':
//console.log('vimeoid');

var player_id = pluginid + "_player";
pluginMediaElement.vimeoid = playback.url.substr(playback.url.lastIndexOf('/')+1);

container.innerHTML ='<iframe src="http://player.vimeo.com/video/' + pluginMediaElement.vimeoid + '?portrait=0&byline=0&title=0" width="' + width +'" height="' + height +'" frameborder="0" class="mejs-shim"></iframe>';

/*
container.innerHTML =
'<object width="' + width + '" height="' + height + '" class="mejs-shim">' +
'<param name="allowfullscreen" value="true" />' +
'<param name="allowscriptaccess" value="always" />' +
'<param name="flashvars" value="api=1" />' +
'<param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=' + pluginMediaElement.vimeoid + '&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1&amp;autoplay=0&amp;loop=0" />' +
'<embed src="//vimeo.com/moogaloop.swf?api=1&amp;clip_id=' + pluginMediaElement.vimeoid + '&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1&amp;autoplay=0&amp;loop=0" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="' + width + '" height="' + height + '" class="mejs-shim"></embed>' +
'</object>';
*/

container.innerHTML ='<iframe src="//player.vimeo.com/video/' + pluginMediaElement.vimeoid + '?api=1&portrait=0&byline=0&title=0&player_id=' + player_id + '" width="' + width +'" height="' + height +'" frameborder="0" class="mejs-shim" id="' + player_id + '"></iframe>';
if (typeof($f) == 'function') { // froogaloop available
var player = $f(container.childNodes[0]);
player.addEvent('ready', function() {
player.playVideo = function() {
player.api('play');
};
player.pauseVideo = function() {
player.api('pause');
};
player.seekTo = function(seconds) {
player.api('seekTo', seconds);
};
function createEvent(player, pluginMediaElement, eventName, e) {
var obj = {
type: eventName,
target: pluginMediaElement
};
if (eventName == 'timeupdate') {
pluginMediaElement.currentTime = obj.currentTime = e.seconds;
pluginMediaElement.duration = obj.duration = e.duration;
}
pluginMediaElement.dispatchEvent(obj.type, obj);
}
player.addEvent('play', function() {
createEvent(player, pluginMediaElement, 'play');
createEvent(player, pluginMediaElement, 'playing');
});
player.addEvent('pause', function() {
createEvent(player, pluginMediaElement, 'pause');
});

player.addEvent('finish', function() {
createEvent(player, pluginMediaElement, 'ended');
});
player.addEvent('playProgress', function(e) {
createEvent(player, pluginMediaElement, 'timeupdate', e);
});
pluginMediaElement.pluginApi = player;

// init mejs
mejs.MediaPluginBridge.initPlugin(pluginid);

});
}
else {
console.warn("You need to include froogaloop for vimeo to work");
}
break;
}
// hide original element
Expand Down Expand Up @@ -775,7 +809,7 @@ mejs.YouTubeApi = {
},
length: 1
};

}

// send event up the chain
Expand Down

0 comments on commit ab9aa89

Please sign in to comment.