收藏
回答

hevc编码的视频使用下载api,显示保存成功但是相册没有这个视频,实际上是失败?

   uni.downloadFile({

            url: detail.value.imageUrl,

            success: (res) => {

                if (res.statusCode === 200) {

                    if (detail.value.mediaType === 2) {

                        // 视频保存:需确保临时文件带 .mp4 后缀,否则部分系统保存成功但相册无视频

                        const tempPath = res.tempFilePath;

                        const saveVideo = (filePath) => {

                            uni.saveVideoToPhotosAlbum({

                                filePath: filePath,

                                success: () => {

                                    uni.hideLoading();

                                    uni.showToast({

                                        title: '已保存到相册',

                                        icon: 'success'

                                    });

                                },

                                fail: (err) => {

                                    uni.hideLoading();

                                    handleSaveError(err);

                                }

                            });

                        };

                        if (!tempPath.endsWith('.mp4')) {

                            const fs = uni.getFileSystemManager();

                            const targetPath = `${wx.env.USER_DATA_PATH}/wallpaper_${Date.now()}.mp4`;

                            fs.copyFile({

                                srcPath: tempPath,

                                destPath: targetPath,

                                success: () => {

                                    saveVideo(targetPath);

                                },

                                fail: () => {

                                    // 复制失败则用原路径尝试保存

                                    saveVideo(tempPath);

                                }

                            });

                        } else {

                            saveVideo(tempPath);

                        }

                    } else {

                        // 图片保存

                        uni.saveImageToPhotosAlbum({

                            filePath: res.tempFilePath,

                            success: () => {

                                uni.hideLoading();

                                uni.showToast({

                                    title: '已保存到相册',

                                    icon: 'success'

                                });

                            },

                            fail: (err) => {

                                uni.hideLoading();

                                handleSaveError(err);

                            }

                        });

                    }

                }

            },

            fail: () => {

                uni.hideLoading();

                uni.showToast({

                    title: '下载失败',

                    icon: 'none'

                });

            }

        });


回答关注问题邀请回答
收藏

1 个回答

  • 智能回答 智能回答 本次回答由AI生成
    04-23
    有用
    回复 1
    • MR.YAN
      MR.YAN
      04-23
      没有fail,走的成功回调
      04-23
      回复
登录 后发表内容