提交 511c004c 编写于 作者: D DCloud_LXH

chore(App): chooseImage、chooseVideo 优化

上级 3abb8b2a
......@@ -133,7 +133,7 @@ async function build (args, api, options) {
log()
if (!runByHBuilderX && !runByAliIde) {
logWithSpinner(uniI18n.__('pluginUni.startCompileProjectToPlatform', { 0: process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM, 1: process.env.UNI_MP_PLUGIN ? uniI18n.__('platform') : uniI18n.__('plugin') }))
logWithSpinner(uniI18n.__('pluginUni.startCompileProjectToPlatform', { 0: process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM, 1: process.env.UNI_MP_PLUGIN ? uniI18n.__('plugin') : uniI18n.__('platform') }))
}
const targetDir = api.resolve(options.outputDir)
......
......@@ -7,8 +7,7 @@ import {
} from '../../bridge'
import {
warpPlusErrorCallback,
getFileName
warpPlusErrorCallback
} from '../util'
import {
......@@ -28,24 +27,6 @@ function getFileInfo (filePath) {
})
}
function compressImage (tempFilePath) {
const dstPath = `${TEMP_PATH}/compressed/${Date.now()}_${getFileName(tempFilePath)}`
return new Promise((resolve) => {
plus.nativeUI.showWaiting()
plus.zip.compressImage({
src: tempFilePath,
dst: dstPath,
overwrite: true
}, () => {
plus.nativeUI.closeWaiting()
resolve(dstPath)
}, () => {
plus.nativeUI.closeWaiting()
resolve(tempFilePath)
})
})
}
export function chooseImage ({
count,
sizeType,
......@@ -57,7 +38,6 @@ export function chooseImage ({
function successCallback (paths) {
const tempFiles = []
const tempFilePaths = []
// plus.zip.compressImage 压缩文件并发调用在iOS端容易出现问题(图像错误、闪退),改为队列执行
Promise.all(paths.map((path) => getFileInfo(path)))
.then((filesInfo) => {
filesInfo.forEach((file, index) => {
......@@ -77,25 +57,12 @@ export function chooseImage ({
function openCamera () {
const camera = plus.camera.getCamera()
camera.captureImage(path => {
// fix By Lxh 暂时添加拍照压缩逻辑,等客户端增加逻辑后修改
// 判断是否需要压缩
if (sizeType && sizeType.includes('compressed')) {
return getFileInfo(path).then(({ size }) => {
// 压缩阈值 0.5 兆
const THRESHOLD = 1024 * 1024 * 0.5
return size && size > THRESHOLD
? compressImage(path).then(dstPath => successCallback([dstPath]))
: successCallback([path])
}).catch(errorCallback)
}
return successCallback([path])
},
errorCallback, {
camera.captureImage(path => successCallback([path]),
errorCallback, {
filename: TEMP_PATH + '/camera/',
resolution: 'high',
crop
crop,
sizeType
})
}
......
......@@ -7,8 +7,7 @@ import {
} from '../../bridge'
import {
warpPlusErrorCallback,
getFileName
warpPlusErrorCallback
} from '../util'
import {
......@@ -24,40 +23,20 @@ export function chooseVideo ({
const errorCallback = warpPlusErrorCallback(callbackId, 'chooseVideo', 'cancel')
function successCallback (tempFilePath = '') {
const filename = `${TEMP_PATH}/compressed/${Date.now()}_${getFileName(tempFilePath)}`
const compressVideo = compressed ? new Promise((resolve) => {
plus.zip.compressVideo({
src: tempFilePath,
filename,
quality: 'medium'
}, ({ tempFilePath }) => {
resolve(tempFilePath)
}, () => {
resolve(tempFilePath)
})
}) : Promise.resolve(tempFilePath)
if (compressed) {
plus.nativeUI.showWaiting()
}
compressVideo.then(tempFilePath => {
if (compressed) {
plus.nativeUI.closeWaiting()
}
plus.io.getVideoInfo({
filePath: tempFilePath,
success (videoInfo) {
const result = {
errMsg: 'chooseVideo:ok',
tempFilePath: tempFilePath
}
result.size = videoInfo.size
result.duration = videoInfo.duration
result.width = videoInfo.width
result.height = videoInfo.height
invoke(callbackId, result)
},
fail: errorCallback
})
plus.io.getVideoInfo({
filePath: tempFilePath,
success (videoInfo) {
const result = {
errMsg: 'chooseVideo:ok',
tempFilePath: tempFilePath
}
result.size = videoInfo.size
result.duration = videoInfo.duration
result.width = videoInfo.width
result.height = videoInfo.height
invoke(callbackId, result)
},
fail: errorCallback
})
}
......@@ -69,7 +48,8 @@ export function chooseVideo ({
multiple: true,
maximum: 1,
filename: TEMP_PATH + '/gallery/',
permissionAlert: true
permissionAlert: true,
videoCompress: compressed
})
}
......@@ -78,7 +58,8 @@ export function chooseVideo ({
plusCamera.startVideoCapture(successCallback, errorCallback, {
index: camera === 'front' ? 2 : 1,
videoMaximumDuration: maxDuration,
filename: TEMP_PATH + '/camera/'
filename: TEMP_PATH + '/camera/',
videoCompress: compressed
})
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册