Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Youtube HTML5 autoplay fix [Finishes #86721652] #255

Merged
merged 3 commits into from Feb 4, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/js/html5/providers/jwplayer.html5.youtube.js
Expand Up @@ -169,6 +169,19 @@
});
}

// Returns a function that is the composition of a list of functions, each
// consuming the return value of the function that follows.
function _composeCallbacks() {
var args = arguments;
var start = args.length - 1;
return function() {
var i = start;
var result = args[start].apply(this, arguments);
while (i--) { result = args[i].call(this, result); }
return result;
};
}

function _embedYoutubePlayer(videoId, playerVars) {
if (!videoId) {
throw 'invalid Youtube ID';
Expand Down Expand Up @@ -371,10 +384,15 @@
}

if (!_youtubePlayer.getPlayerState) {
_youtubePlayerReadyCallback = function() {
var onStart = function() {
_volumeHandler();
_this.load(item);
};
if (_youtubePlayerReadyCallback) {
_youtubePlayerReadyCallback = _composeCallbacks(onStart, _youtubePlayerReadyCallback);
} else {
_youtubePlayerReadyCallback = onStart;
}
return;
}

Expand Down Expand Up @@ -416,8 +434,14 @@
if (_requiresUserInteraction) {
return;
}
if (_youtubePlayer.playVideo) {
if (_youtubePlayer && _youtubePlayer.playVideo) {
_youtubePlayer.playVideo();
} else { // If the _youtubePlayer isn't setup, then play when we're ready
if (_youtubePlayerReadyCallback) {
_youtubePlayerReadyCallback = _composeCallbacks(this.play, _youtubePlayerReadyCallback);
} else {
_youtubePlayerReadyCallback = this.play;
}
}
};

Expand Down