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

download

pc端下载插件。源码

pluginName: download

该插件默认隐藏,如需开启如下配置playerConfig

const player = new Player({
  ...,
  download: true //显示下载按钮
})

提示

本插件采用开源 downloadjs 实现下载功能。基于该开源插件实现的原理,xgplayer无法提供统一下载进度事件。如果有强烈业务需求,可以参考 downloadjs xmlHttpRequest 逻辑实现一个自定义的下载插件

config

position

插件DOM挂载位置,默认为player.controls.right

index

  • @type: Number
  • default: 3

插件DOM在挂载点内的排序,默认为3,越小越靠前(若index相同,后实例化的插件会被放置在前面)

disable

  • @type: Boolean
  • default: true

是否禁用,默认true

该配置项可通过playerConfig.download设置布尔值控制,默认值是false, 例如:

const playerConfig = {
  download: true //显示下载按钮
  ...
}

saveAsOptions(v3.0.24+)

  • @type: Object
  • default: SaveAsOptions

下载器配置:

type SaveAsOptions = {
    fileName?: string | undefined; // 下载的文件名
    headers?: any; // 自定义header
    withCredentials?: boolean | undefined; // 是否携带cookie凭证
    timeout?: number | undefined; // 超时时间配置
    beforeRequest?: Function | undefined; // 下载请求前,可针对 xmlHttpRequest的其他处理
}

示例:

new Player({
  download: {
    disable: false,
    saveAsOptions: {
      withCredentials: true, // 不需要cookie的时候不要配置,否则可能会有Response头 Access-Control-Allow-Origin 要求
      beforeRequest: function(xhr) {
        xhr.setRequestHeader('Authorization', 'Bearer 1234567890')
        xhr.withCredentials = true
      }
    }
  },
});