小程序开放平台

文档中心
暂无目录

xhs.saveVideoToPhotosAlbum

更新时间:2025-04-10 17:49:38

以Promise风格调用: 支持

保存视频到系统相册。支持mp4视频格式。

参数

Object object

属性
类型
默认值
必填
说明
filePathstring视频文件路径,可以是临时文件路径也可以是永久文件路径 (本地路径)
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

object.success 回调函数

属性
类型
说明
errMsgstring

实例代码

function saveVideoToPhotosAlbum(filePath) {
  return new Promise((resolve, reject) => {
    xhs.saveVideoToPhotosAlbum({
      filePath, // 视频文件路径
      success: (res) => resolve(res),
      fail: (err) => reject(err),
    });
  });
}

// 调用示例
const videoPath = '/path/to/video.mp4'; // 替换为实际的视频文件路径

saveVideoToPhotosAlbum(videoPath)
  .then((res) => {
    console.log('视频保存成功:', res.errMsg);
  })
  .catch((err) => {
    console.error('视频保存失败:', err);
  });