Skip to content

Commit 360b5eb

Browse files
committed
Merge branch 'develop' of https://github.com/ableplayer/ableplayer into develop
2 parents 9cee3c8 + b92a105 commit 360b5eb

File tree

6 files changed

+57
-37
lines changed

6 files changed

+57
-37
lines changed

scripts/ableplayer-base.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ var AblePlayerInstances = [];
248248
var youTubeId = $(media).data('youtube-id');
249249
if ( youTubeId !== undefined && youTubeId !== "") {
250250
this.youTubeId = this.getYouTubeId(youTubeId);
251+
if ( ! this.hasPoster ) {
252+
let poster = this.getYouTubePosterUrl(this.youTubeId,'1200');
253+
$(media).attr( 'poster', poster );
254+
this.hasPoster = true;
255+
}
251256
}
252257

253258
var youTubeDescId = $(media).data('youtube-desc-id');
@@ -267,6 +272,11 @@ var AblePlayerInstances = [];
267272
var vimeoId = $(media).data('vimeo-id');
268273
if ( vimeoId !== undefined && vimeoId !== "") {
269274
this.vimeoId = this.getVimeoId(vimeoId);
275+
if ( ! this.hasPoster ) {
276+
let poster = thisObj.getVimeoPosterUrl(this.vimeoId,'1200');
277+
$(media).attr( 'poster', poster );
278+
this.hasPoster = true;
279+
}
270280
}
271281
var vimeoDescId = $(media).data('vimeo-desc-id');
272282
if ( vimeoDescId !== undefined && vimeoDescId !== "") {

scripts/buildplayer.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@
33
AblePlayer.prototype.injectPlayerCode = function() {
44

55
// create and inject surrounding HTML structure
6-
// If iOS:
7-
// If video:
8-
// iOS does not support any of the player's functionality
9-
// - everything plays in its own player
10-
// Therefore, AblePlayer is not loaded & all functionality is disabled
11-
// (this all determined. If this is iOS && video, this function is never called)
6+
// If iOS & video:
7+
// iOS does not support any of the player's functionality - everything plays in its own player
8+
// Therefore, AblePlayer is not loaded & all functionality is disabled
9+
// (this all determined. If this is iOS && video, this function is never called)
1210

1311
var captionsContainer;
14-
15-
// create three wrappers and wrap them around the media element.
16-
// From inner to outer:
12+
// Wrappers, from inner to outer:
1713
// $mediaContainer - contains the original media element
1814
// $ableDiv - contains the media player and all its objects (e.g., captions, controls, descriptions)
1915
// $ableWrapper - contains additional widgets (e.g., transcript window, sign window)

scripts/misc.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,26 @@
141141
});
142142
}
143143

144+
AblePlayer.prototype.getScript = function( source, callback ) {
145+
var script = document.createElement('script');
146+
var prior = document.getElementsByTagName('script')[0];
147+
script.async = 1;
148+
149+
script.onload = script.onreadystatechange = function( _, isAbort ) {
150+
if ( isAbort || !script.readyState || /loaded|complete/.test(script.readyState) ) {
151+
script.onload = script.onreadystatechange = null;
152+
script = undefined;
153+
154+
if ( !isAbort && callback ) {
155+
setTimeout(callback, 0);
156+
}
157+
}
158+
};
159+
160+
script.src = source;
161+
prior.parentNode.insertBefore(script, prior);
162+
}
163+
144164
AblePlayer.prototype.hasAttr = function (object, attribute) {
145165
// surprisingly, there is no hasAttr() function in Jquery as of 3.2.1
146166
// return true if object has attribute; otherwise false

scripts/sign.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@
134134
});
135135
} else {
136136
// Has another player already started loading the script? If so, abort...
137-
if (!AblePlayer.loadingYouTubeIframeAPI) {
138-
$.getScript('https://www.youtube.com/iframe_api').fail(function () {
139-
deferred.reject();
137+
if ( ! AblePlayer.loadingYouTubeIframeAPI ) {
138+
thisObj.getScript('https://www.youtube.com/iframe_api', function () {
139+
console.log( 'YouTube API loaded' );
140140
});
141141
}
142142

scripts/vimeo.js

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -228,29 +228,23 @@
228228

229229
AblePlayer.prototype.getVimeoPosterUrl = function (vimeoId, width) {
230230

231-
// this is a placeholder, copied from getYouTubePosterUrl()
232-
// Vimeo doesn't seem to have anything similar,
233-
// Vimeo API for images: https://vimeo.com/api/v2/video/328769500.json
234-
// will require an unauthenticated API query.
235-
236-
// return a URL for retrieving a YouTube poster image
237-
// supported values of width: 120, 320, 480, 640
238-
239-
var url = 'https://img.youtube.com/vi/' + youTubeId;
240-
if (width == '120') {
241-
// default (small) thumbnail, 120 x 90
242-
return url + '/default.jpg';
243-
} else if (width == '320') {
244-
// medium quality thumbnail, 320 x 180
245-
return url + '/hqdefault.jpg';
246-
} else if (width == '480') {
247-
// high quality thumbnail, 480 x 360
248-
return url + '/hqdefault.jpg';
249-
} else if (width == '640') {
250-
// standard definition poster image, 640 x 480
251-
return url + '/sddefault.jpg';
252-
}
253-
return false;
231+
// Vimeo Oembed only returns a 640px width image. Hope at some point there's an alternative.
232+
var url = 'http://vimeo.com/api/oembed.json?url=https://vimeo.com/' + vimeoId, imageUrl = '';
233+
console.log( url );
234+
fetch( url ).then( response => {
235+
236+
return response.json();
237+
})
238+
.then( json => {
239+
imageUrl = json.thumbnail_url;
240+
})
241+
.catch( error => {
242+
if (thisObj.debug) {
243+
console.log( 'Vimeo API query: ' + error );
244+
}
245+
});
246+
247+
return imageUrl;
254248
};
255249

256250
AblePlayer.prototype.getVimeoId = function (url) {

scripts/youtube.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
} else {
2323
// Has another player already started loading the script? If so, abort...
2424
if (!AblePlayer.loadingYouTubeIframeAPI) {
25-
$.getScript('https://www.youtube.com/iframe_api').fail(function () {
26-
deferred.reject();
25+
thisObj.getScript('https://www.youtube.com/iframe_api', function () {
26+
console.log( 'YouTube API loaded' );
2727
});
2828
}
2929

0 commit comments

Comments
 (0)