Chuyển tới nội dung chính

compressVideo

compressVideo là API dùng để nén video khiến chúng có dung lượng nhỏ hơn.

Thuộc tínhKiểu dữ liệuBắt buộcMô tả
filePathStringĐường dẫn tới tập tin video cần nén
optionsVideoCompressOptionsOptions cho việc nén video
successFunctionCallback function khi nén video thành công
failFunctionCallback function khi nén video bất thành
completeFunctionCallback function khi gọi API hoàn tất bất kể nén video thành công hay thất bại.

Callback function payload

Thuộc tínhKiểu dữ liệuMô tả
filePathstringChứa đường đẫn tạm thời của video đã được nén

VideoCompressOptions payload

Thuộc tínhKiểu dữ liệuMô tả
maxWidthIntegerKích thước chiều rộng tối đa

Ví dụ

import apis from '@v-miniapp/apis'

function onCompressVideo() {
apis.chooseVideo({
success: res => {
// Automatically preview images after selection
if (res.filePaths[0].length > 0) {
apis.compressVideo({
filePath: res.filePaths[0],
options: { maxWidth: 640 },
success: (compressRes: any) => {
apis.alert({ title: JSON.stringify(compressRes) })
// Automatically preview images after selection
const filePath = compressRes.filePath
apis.previewVideo({
url: filePath,
})
},
fail: (e: any) => {
setStatus('fail')
setResponse({ error: e })
},
})
}
},
fail: e => {
apis.alert({ content: JSON.stringify(e) })
console.log(e)
},
})
}