问题描述:
从接口获取的图片和视频,在小程序中预览,图片可以正常显示,视频所占区域一直处于加载的状态,且无法正常播放。
解决方法:
需要调用wx.downloadFile接口,将视频下载到本地,然后再预览。
const query = this.$route.query;
wx.downloadFile({
//先把文件复制到可操作的文件夹
url: decodeURIComponent(query.url), //源文件
// filePath, //可操作的文件夹路径
success: res => {
const tempFilePath = res.tempFilePath;
setTimeout(() => {
this.file = {
url: tempFilePath,
title: query.title,
description: query.description,
type: query.type
};
wx.hideLoading();
}, 300);
},
fail: () => {}