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

saveVideoToGallery

Bắt đầu hỗ trợ ở phiên bản:

  • SDK: 2.44.0
Lưu ý

Cần xin cấp quyền tại trang Quản lý ứng dụng

import { saveVideoToGallery } from "zmp-sdk/apis";

Lưu video vào thư viện media của thiết bị.

Ví dụ

Thông báo một lần sau khi lưu video xong:

await saveVideoToGallery({
videoUrl:
"https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4",
});
console.log("Lưu video thành công!");

Xử lý lỗi khi lưu video:

try {
await saveVideoToGallery({
videoUrl:
"https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4",
});
} catch (error) {
console.error(error);
}

Báo cáo tiến độ lưu video:

await saveVideoToGallery({
videoUrl:
"https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4",
onProgress: (progress) => {
console.log(`Đã lưu được ${progress}%...`);
},
});
console.log("Lưu video thành công!");
Xem hướng dẫn xử lý lỗi và bảng mô tả chi tiết mã lỗi tại đây.

Tham số

Truyền tham số vào API dưới dạng object chứa các thuộc tính:

NameTypeDefaultDescription
videoUrlstring

Đường dẫn của video cần lưu.

onProgress(progress: number) => void

Callback function tiến độ tải file. Với progress là số từ 0 đến 100%.

saveVideoToGallery

zi-chevron-up
miniapp-logo

Khám phá