西瓜播放器 HTML5 video video.js 播放器 HTML5播放器 mp4 hls hls.js flv flv.js dash dash.js 无缝切换

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: String
  • default: POSITIONS.ROOT_RIGHTFor specific enumeration values, please see plugin-positions

The plugin Dom mount location

index

  • @type: Number
  • default: 3

display order in controlBar

disable

  • @type: Boolean
  • default: 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

  • @type: Object
  • default: 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
      }
    }
  },
});