Skip to content

Commit

Permalink
fix: fix screenShot 保存文件名称不支持国际化问题
Browse files Browse the repository at this point in the history
  • Loading branch information
yiwen03 committed Oct 12, 2022
1 parent c47b7d4 commit 3f65b28
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 10 deletions.
1 change: 0 additions & 1 deletion packages/xgplayer/browser/core_player.js.map

This file was deleted.

1 change: 0 additions & 1 deletion packages/xgplayer/browser/index.js.map

This file was deleted.

1 change: 0 additions & 1 deletion packages/xgplayer/browser/simple_player.js.map

This file was deleted.

1 change: 0 additions & 1 deletion packages/xgplayer/es/core_player.js.map

This file was deleted.

1 change: 0 additions & 1 deletion packages/xgplayer/es/index.js.map

This file was deleted.

1 change: 0 additions & 1 deletion packages/xgplayer/es/simple_player.js.map

This file was deleted.

17 changes: 13 additions & 4 deletions packages/xgplayer/src/controls/screenShot.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
let screenShot = function () {
let player = this
let screenShotOptions = player.config.screenShot
let callBack = null
if (!screenShotOptions) {
return
}

player.video.setAttribute('crossOrigin', 'anonymous')

let encoderOptions = 0.92
if(screenShotOptions.quality || screenShotOptions.quality === 0) {

if (screenShotOptions.quality || screenShotOptions.quality === 0) {
encoderOptions = screenShotOptions.quality
}
let type = screenShotOptions.type === undefined ? 'image/png' : screenShotOptions.type
Expand All @@ -17,9 +19,9 @@ let screenShot = function () {
let canvas = document.createElement('canvas')
let canvasCtx = canvas.getContext('2d')
let img = new Image()
canvas.width = this.config.width || 600
canvas.height = this.config.height || 337.5

canvas.width = this.config.width || 600
canvas.height = this.config.height || 337.5
let saveScreenShot = function (data, filename) {
let saveLink = document.createElement('a')
saveLink.href = data
Expand All @@ -33,12 +35,19 @@ let screenShot = function () {
save = screenShotOptions.saveImg === undefined ? save : screenShotOptions.saveImg
canvas.width = player.video.videoWidth || 600
canvas.height = player.video.videoHeight || 337.5
callBack = screenShotOptions.callBack
img.onload = (function () {
canvasCtx.drawImage(player.video, 0, 0, canvas.width, canvas.height)
img.src = canvas.toDataURL(type, encoderOptions).replace(type, 'image/octet-stream')
let screenShotImg = img.src.replace(/^data:image\/[^;]+/, 'data:application/octet-stream')
let saveFileName = screenShotOptions.fileName || player.lang.SCREENSHOT

player.emit('screenShot', screenShotImg)
save && saveScreenShot(screenShotImg, '截图' + format)
if (save && callBack) {
callBack(screenShotImg, saveFileName, format)
} else {
save && saveScreenShot(screenShotImg, saveFileName + format)
}
})()
}
player.on('screenShotBtnClick', player.screenShot)
Expand Down

0 comments on commit 3f65b28

Please sign in to comment.