core
    正在准备搜索索引...

    接口 YmxMedia

    媒体

    interface YmxMedia {
        chooseMedia(data: ChooseMediaData): Promise<ChooseMediaResult>;
        compressImage(data: CompressImageData): Promise<CompressImageResult>;
        compressVideo(data: CompressVideoData): Promise<CompressVideoResult>;
        getImageInfo(data: GetImageInfoData): Promise<GetImageInfoResult>;
        getVideoInfo(data: GetVideoInfoData): Promise<GetVideoInfoResult>;
        saveImageToPhotosAlbum(data: SaveMediaToPhotosAlbumData): Promise<void>;
        saveVideoToPhotosAlbum(data: SaveMediaToPhotosAlbumData): Promise<void>;
    }

    层级 (查看层级一览)

    索引

    方法

    • 拍摄或从手机相册中选择图片或视频

      参数

      返回 Promise<ChooseMediaResult>

      ymx.chooseMedia({
      // 相册
      sourceType: ['album'],
      // 选一个
      count: 1,
      mediaType: ['image']
      }).then(res => {
      alert(JSON.stringify(res));
      });
      ymx.chooseMedia({
      // 相册
      sourceType: ['album'],
      // 选 3 个
      count: 3,
      mediaType: ['image']
      }).then(res => {
      alert(JSON.stringify(res));
      });
      ymx.chooseMedia({
      // 拍照
      sourceType: ['camera'],
      // 后置摄像头
      camera: 'back',
      mediaType: ['image']
      }).then(res => {
      alert(JSON.stringify(res));
      });
      ymx.chooseMedia({
      // 拍照
      sourceType: ['camera'],
      // 前置摄像头
      camera: 'front',
      mediaType: ['video']
      }).then(res => {
      alert(JSON.stringify(res));
      });
    • 压缩图片接口,可选压缩质量。

      参数

      返回 Promise<CompressImageResult>

      ymx.chooseMedia({
      mediaType: ['image'],
      count: 1
      }).then(async (choose) => {
      // 压缩图片
      const res = await ymx.compressImage({
      src: choose.tempFiles[0].tempFilePath,
      compressedWidth: 480
      });
      alert(JSON.stringify(res));
      });
    • 压缩视频接口。开发者可指定压缩质量 quality 进行压缩。当需要更精细的控制时,可指定 bitrate、fps、和 resolution,当 quality 传入时,这三个参数将被忽略。原视频的相关信息可通过 getVideoInfo 获取。

      参数

      返回 Promise<CompressVideoResult>

      ymx.chooseMedia({
      mediaType: ['video'],
      count: 1
      }).then(async (choose) => {
      // 压缩视频
      const res = await ymx.compressVideo({
      src: choose.tempFiles[0].tempFilePath,
      quality: 'medium'
      });
      alert(JSON.stringify(res));
      });
    • 获取图片信息。

      参数

      返回 Promise<GetImageInfoResult>

      ymx.chooseMedia({
      mediaType: ['image'],
      count: 1
      }).then(async (choose) => {
      // 获取图片信息
      const res = await ymx.getImageInfo({
      src: choose.tempFiles[0].tempFilePath
      });
      alert(JSON.stringify(res));
      });
      ymx.getImageInfo({
      src: 'https://i.cdn.yimenapp.com/sys/1.jpg'
      }).then(res => {
      alert(JSON.stringify(res));
      });
    • 获取视频详细信息。

      参数

      返回 Promise<GetVideoInfoResult>

      ymx.chooseMedia({
      mediaType: ['video'],
      count: 1
      }).then(async (choose) => {
      // 获取视频信息
      const res = await ymx.getVideoInfo({
      src: choose.tempFiles[0].tempFilePath
      });
      alert(JSON.stringify(res));
      });
    • 保存图片到系统相册

      返回 Promise<void>

      ymx.downloadFile({
      url: 'https://i.cdn.yimenapp.com/sys/2.jpg'
      }).then(async (file) => {
      alert('已下载图片');
      // 保存图片到相册
      await ymx.saveImageToPhotosAlbum({
      filePath: file.tempFilePath
      });
      alert('已保存图片到相册');
      })
    • 保存视频到系统相册

      返回 Promise<void>

      ymx.downloadFile({
      url: 'https://cdn.myapp.ltd/sys/sunflower.mp4'
      }).then(async (file) => {
      alert('已下载视频');
      // 保存视频到相册
      await ymx.saveVideoToPhotosAlbum({
      filePath: file.tempFilePath
      });
      alert('已保存视频到相册');
      })