compressVideo
compressVideo là API dùng để nén video khiến chúng có dung lượng nhỏ hơn.
| Thuộc tính | Kiểu dữ liệu | Bắt buộc | Mô tả |
|---|---|---|---|
| filePath | String | ✓ | Đường dẫn tới tập tin video cần nén |
| options | VideoCompressOptions | Options cho việc nén video | |
| success | Function | Callback function khi nén video thành công | |
| fail | Function | Callback function khi nén video bất thành | |
| complete | Function | Callback 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ính | Kiểu dữ liệu | Mô tả |
|---|---|---|
| filePath | string | Chứa đường đẫn tạm thời của video đã được nén |
VideoCompressOptions payload
| Thuộc tính | Kiểu dữ liệu | Mô tả |
|---|---|---|
| maxWidth | Integer | Kí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)
},
})
}