Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into docs-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
rafa8626 committed Sep 1, 2016
2 parents 5833adb + f95de34 commit dc8a0f6
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/js/me-mediaelements.js
Expand Up @@ -315,7 +315,7 @@ mejs.PluginMediaElement.prototype = {
if (this.hasAttribute(name)) {
return this.attributes[name];
}
return '';
return null;
},
setAttribute: function(name, value){
this.attributes[name] = value;
Expand Down
31 changes: 18 additions & 13 deletions src/js/me-shim.js
Expand Up @@ -386,7 +386,7 @@ mejs.HtmlMediaElementShim = {
initVars;

// copy tagName from html media element
pluginMediaElement.tagName = htmlMediaElement.tagName
pluginMediaElement.tagName = htmlMediaElement.tagName;

// copy attributes from html media element to plugin media element
for (var i = 0; i < htmlMediaElement.attributes.length; i++) {
Expand Down Expand Up @@ -617,7 +617,6 @@ mejs.HtmlMediaElementShim = {
} else if (mejs.PluginDetector.hasPluginVersion('flash', [10,0,0]) ) {
mejs.YouTubeApi.createFlash(youtubeSettings, options);
}

break;

// DEMO Code. Does NOT work.
Expand All @@ -634,19 +633,19 @@ mejs.HtmlMediaElementShim = {

player.playVideo = function() {
player.api( 'play' );
}
};
player.stopVideo = function() {
player.api( 'unload' );
}
};
player.pauseVideo = function() {
player.api( 'pause' );
}
};
player.seekTo = function( seconds ) {
player.api( 'seekTo', seconds );
}
};
player.setVolume = function( volume ) {
player.api( 'setVolume', volume );
}
};
player.setMuted = function( muted ) {
if( muted ) {
player.lastVolume = player.api( 'getVolume' );
Expand All @@ -655,11 +654,11 @@ mejs.HtmlMediaElementShim = {
player.api( 'setVolume', player.lastVolume );
delete player.lastVolume;
}
}
};
// parity with YT player
player.getPlayerState = function() {
return playerState;
}
};

function createEvent(player, pluginMediaElement, eventName, e) {
var event = {
Expand Down Expand Up @@ -805,26 +804,32 @@ mejs.YouTubeApi = {
height: settings.height,
width: settings.width,
videoId: settings.videoId,
playerVars: {controls:0,wmode:'transparent'},
playerVars: {controls:0, wmode:'transparent'},
events: {
'onReady': function() {
'onReady': function(e) {

// wrapper to match
player.setVideoSize = function(width, height) {
player.setSize(width, height);
}
};

// hook up iframe object to MEjs
settings.pluginMediaElement.pluginApi = player;
settings.pluginMediaElement.pluginElement = document.getElementById(settings.containerId);

// init mejs
pluginMediaElement.success(pluginMediaElement, pluginMediaElement.pluginElement);

mejs.YouTubeApi.createEvent(player, pluginMediaElement, 'canplay');

// create timer
setInterval(function() {
mejs.YouTubeApi.createEvent(player, pluginMediaElement, 'timeupdate');
}, 250);
}, 250);

if (typeof pluginMediaElement.attributes.autoplay !== 'undefined') {
player.playVideo();
}
},
'onStateChange': function(e) {

Expand Down
41 changes: 24 additions & 17 deletions src/js/mep-feature-progress.js
@@ -1,38 +1,41 @@
(function($) {

$.extend(mejs.MepDefaults, {
progessHelpText: mejs.i18n.t(
// Enable tooltip that shows time in progress bar
enableProgressTooltip: true,
progressHelpText: mejs.i18n.t(
'Use Left/Right Arrow keys to advance one second, Up/Down arrows to advance ten seconds.')
});

// progress/loaded bar
$.extend(MediaElementPlayer.prototype, {
buildprogress: function(player, controls, layers, media) {

var
t = this,
mouseIsDown = false,
mouseIsOver = false,
lastKeyPressTime = 0,
startedPaused = false,
autoRewindInitial = player.options.autoRewind,
tooltip = player.options.enableProgressTooltip ? '<span class="mejs-time-float">' +
'<span class="mejs-time-float-current">00:00</span>' +
'<span class="mejs-time-float-corner"></span>' +
'</span>' : "";

$('<div class="mejs-time-rail">' +
'<span class="mejs-time-total mejs-time-slider">' +
//'<span class="mejs-offscreen">' + this.options.progessHelpText + '</span>' +
//'<span class="mejs-offscreen">' + this.options.progressHelpText + '</span>' +
'<span class="mejs-time-buffering"></span>' +
'<span class="mejs-time-loaded"></span>' +
'<span class="mejs-time-current"></span>' +
'<span class="mejs-time-handle"></span>' +
'<span class="mejs-time-float">' +
'<span class="mejs-time-float-current">00:00</span>' +
'<span class="mejs-time-float-corner"></span>' +
'</span>' +
tooltip +
'</span>' +
'</div>')
.appendTo(controls);
controls.find('.mejs-time-buffering').hide();

var
t = this,
mouseIsDown = false,
mouseIsOver = false,
lastKeyPressTime = 0,
startedPaused = false,
autoRewindInitial = player.options.autoRewind;

t.total = controls.find('.mejs-time-total');
t.loaded = controls.find('.mejs-time-loaded');
t.current = controls.find('.mejs-time-current');
Expand Down Expand Up @@ -183,7 +186,9 @@
});
t.globalBind('mouseup.dur touchend.dur', function (e) {
mouseIsDown = false;
t.timefloat.hide();
if (typeof t.timefloat !== 'undefined') {
t.timefloat.hide();
}
t.globalUnbind('.dur');
});
}
Expand All @@ -193,15 +198,17 @@
t.globalBind('mousemove.dur', function(e) {
handleMouseMove(e);
});
if (!mejs.MediaFeatures.hasTouch) {
if (typeof t.timefloat !== 'undefined' && !mejs.MediaFeatures.hasTouch) {
t.timefloat.show();
}
})
.bind('mouseleave',function(e) {
mouseIsOver = false;
if (!mouseIsDown) {
t.globalUnbind('.dur');
t.timefloat.hide();
if (typeof t.timefloat !== 'undefined') {
t.timefloat.hide();
}
}
});

Expand Down
47 changes: 46 additions & 1 deletion src/js/mep-player.js
Expand Up @@ -1365,7 +1365,52 @@
return this.media.volume;
},
setSrc: function(src) {
this.media.setSrc(src);
var
t = this;

// If using YouTube, its API is different to load a specific source
if (t.media.pluginType === 'youtube') {
var videoId;

if (typeof src !== 'string') {
var i, media;

for (i=0; i<src.length; i++) {
media = src[i];
if (this.canPlayType(media.type)) {
src = media.src;
break;
}
}
}

// youtu.be url from share button
if (src.lastIndexOf('youtu.be') !== -1) {
videoId = src.substr(src.lastIndexOf('/') + 1);

if (videoId.indexOf('?') !== -1) {
videoId = videoId.substr(0, videoId.indexOf('?'));
}

} else {
// https://www.youtube.com/watch?v=
var videoIdMatch = src.match(/[?&]v=([^&#]+)|&|#|$/);

if (videoIdMatch) {
videoId = videoIdMatch[1];
}
}

if (t.media.getAttribute('autoplay') !== null) {
t.media.pluginApi.loadVideoById(videoId);
} else {
t.media.pluginApi.cueVideoById(videoId);
}

}
else {
t.media.setSrc(src);
}
},
remove: function() {
var t = this, featureIndex, feature;
Expand Down

0 comments on commit dc8a0f6

Please sign in to comment.