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