Allow custom download URL (for streaming, etc)
This commit is contained in:
parent
ebaded66b4
commit
03c9b53232
@ -133,7 +133,7 @@ const defaults = {
|
|||||||
'settings',
|
'settings',
|
||||||
'pip',
|
'pip',
|
||||||
'airplay',
|
'airplay',
|
||||||
'download',
|
// 'download',
|
||||||
'fullscreen',
|
'fullscreen',
|
||||||
],
|
],
|
||||||
settings: ['captions', 'quality', 'speed'],
|
settings: ['captions', 'quality', 'speed'],
|
||||||
@ -186,6 +186,7 @@ const defaults = {
|
|||||||
|
|
||||||
// URLs
|
// URLs
|
||||||
urls: {
|
urls: {
|
||||||
|
download: null,
|
||||||
vimeo: {
|
vimeo: {
|
||||||
sdk: 'https://player.vimeo.com/api/player.js',
|
sdk: 'https://player.vimeo.com/api/player.js',
|
||||||
iframe: 'https://player.vimeo.com/video/{0}?{1}',
|
iframe: 'https://player.vimeo.com/video/{0}?{1}',
|
||||||
|
22
src/js/controls.js
vendored
22
src/js/controls.js
vendored
@ -1229,11 +1229,15 @@ const controls = {
|
|||||||
|
|
||||||
// Set the download link
|
// Set the download link
|
||||||
setDownloadLink() {
|
setDownloadLink() {
|
||||||
// Set download link
|
const button = this.elements.buttons.download;
|
||||||
const { download } = this.elements.buttons;
|
|
||||||
if (is.element(download)) {
|
// Bail if no button
|
||||||
download.setAttribute('href', this.source);
|
if (!is.element(button)) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set download link
|
||||||
|
button.setAttribute('href', this.download);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Build the default HTML
|
// Build the default HTML
|
||||||
@ -1516,15 +1520,13 @@ const controls = {
|
|||||||
if (this.config.controls.includes('download')) {
|
if (this.config.controls.includes('download')) {
|
||||||
const attributes = {
|
const attributes = {
|
||||||
element: 'a',
|
element: 'a',
|
||||||
href: this.source,
|
href: this.download,
|
||||||
target: '_blank',
|
target: '_blank',
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.isHTML5) {
|
const { download } = this.config.urls;
|
||||||
extend(attributes, {
|
|
||||||
download: '',
|
if (!is.url(download) && this.isEmbed) {
|
||||||
});
|
|
||||||
} else if (this.isEmbed) {
|
|
||||||
extend(attributes, {
|
extend(attributes, {
|
||||||
icon: `logo-${this.provider}`,
|
icon: `logo-${this.provider}`,
|
||||||
label: this.provider,
|
label: this.provider,
|
||||||
|
@ -431,7 +431,7 @@ class Listeners {
|
|||||||
controls.updateSetting.call(player, 'quality', null, event.detail.quality);
|
controls.updateSetting.call(player, 'quality', null, event.detail.quality);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update download link
|
// Update download link when ready and if quality changes
|
||||||
on.call(player, player.media, 'ready qualitychange', () => {
|
on.call(player, player.media, 'ready qualitychange', () => {
|
||||||
controls.setDownloadLink.call(player);
|
controls.setDownloadLink.call(player);
|
||||||
});
|
});
|
||||||
|
@ -788,6 +788,15 @@ class Plyr {
|
|||||||
return this.media.currentSrc;
|
return this.media.currentSrc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a download URL (either source or custom)
|
||||||
|
*/
|
||||||
|
get download() {
|
||||||
|
const { download } = this.config.urls;
|
||||||
|
|
||||||
|
return is.url(download) ? download : this.source;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the poster image for a video
|
* Set the poster image for a video
|
||||||
* @param {input} - the URL for the new poster image
|
* @param {input} - the URL for the new poster image
|
||||||
|
@ -31,6 +31,11 @@ const isUrl = input => {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Must be string from here
|
||||||
|
if (!isString(input)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Add the protocol if required
|
// Add the protocol if required
|
||||||
let string = input;
|
let string = input;
|
||||||
if (!input.startsWith('http://') || !input.startsWith('https://')) {
|
if (!input.startsWith('http://') || !input.startsWith('https://')) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user