-
Notifications
You must be signed in to change notification settings - Fork 147
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
Use an existing player if present when video changes. #61
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,13 +184,44 @@ angular.module('youtube-embed', ['ng']) | |
player.id = playerId; | ||
return player; | ||
} | ||
|
||
function isEmpty (obj) { | ||
if (obj == null) return true; | ||
if (Object.keys) return Object.keys(obj).length == 0; | ||
var keys = []; | ||
for (var key in obj) if (_.has(obj, key)) keys.push(key); | ||
return keys.length == 0; | ||
}; | ||
|
||
function loadPlayer () { | ||
if (scope.videoId || scope.playerVars.list) { | ||
// If present, use an existing player | ||
if(scope.player && !isEmpty(scope.player) && scope.player.getIframe() && scope.player.cueVideoById === 'function') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for all of your hard work here @brandly @alexthewilde. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @brandly I believe this method returns the DOM node for the embedded iframe, maybe the intention is to make sure that it exists/is loaded? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The getiframe function doesn't exists. I guess alex forget this one to include |
||
var playerVars = ( playerVars ? playerVars : angular.copy(scope.playerVars) ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how would |
||
playerVars.start = playerVars.start || scope.urlStartTime; | ||
playerVars.end = playerVars.end || scope.urlEndTime; | ||
|
||
// Use cueVideoById() instead of loadVideoById() so the video doesn't | ||
// start to play automatically. | ||
if (scope.videoId) { | ||
scope.player.cueVideoById({ | ||
videoId:scope.videoId, | ||
startSeconds:playerVars.start, | ||
endSeconds:playerVars.end | ||
}); | ||
} | ||
else if(scope.playerVars.list) { | ||
scope.player.cuePlaylist({ | ||
playlist:scope.playerVars.list, | ||
startSeconds:playerVars.start, | ||
endSeconds:playerVars.end | ||
}); | ||
} | ||
} | ||
// Otherwise, create a new player | ||
else if(scope.videoId || scope.playerVars.list) { | ||
if (scope.player && typeof scope.player.destroy === 'function') { | ||
scope.player.destroy(); | ||
} | ||
|
||
scope.player = createPlayer(); | ||
} | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we do
obj.hasOwnProperty(key)
instead of the underscore dependency?