download
Download plugin。SourceCode
pluginName: download
The plugin is hidden by default, if you need to enable it, you can configuration playerConfig as follows:
const player = new Player({
...,
download: true
})
// OR
const player = new Player({
...,
download: {
disable: false,
... // Other configuration items
}
})
TIP
This plugin uses the downloadjs to realize the download function. Based on the principle implemented by this open source plugin, xgplayer cannot provide unified download progress events. If you have strong business needs, you can refer to downloadjs xmlHttpRequest logic to implement a custom download plugin
config
position
@type:Stringdefault:POSITIONS.ROOT_RIGHTFor specific enumeration values, please see plugin-positions
The plugin Dom mount location
index
@type:Numberdefault:3
display order in controlBar
disable
@type:Booleandefault:true
Whether to disable, Default true
This configuration item can be controlled by setting a boolean value through playerConfig.download, with a default value of false. For example:
const playerConfig = {
download: true // Show download button
...
}
saveAsOptions(v3.0.24+)
@type:Objectdefault:SaveAsOptions
Downloader configuration:
type SaveAsOptions = {
fileName?: string | undefined; // Downloaded file name
headers?: any; // Custom headers
withCredentials?: boolean | undefined; // Whether to include cookie credentials
timeout?: number | undefined; // Timeout configuration
beforeRequest?: Function | undefined; // Additional processing for xmlHttpRequest before download request
}
Example:
new Player({
download: {
disable: false,
saveAsOptions: {
withCredentials: true,
beforeRequest: function(xhr) {
xhr.setRequestHeader('Authorization', 'Bearer 1234567890')
xhr.withCredentials = true
}
}
},
});