14
This commit is contained in:
@@ -96,9 +96,7 @@
|
||||
coverDownloadProgress: 0,
|
||||
videoDownloading: false,
|
||||
videoDownloadProgress: 0,
|
||||
coverExists: false,
|
||||
videoExists: false,
|
||||
coverCachePath:"",
|
||||
videoCachePath:"",
|
||||
previewVideoFlag: false,
|
||||
previewVideoSrc: "",
|
||||
@@ -121,44 +119,19 @@
|
||||
// 如果有远程 snapshotUrl,则下载到 coverCachePath
|
||||
const snapshotUrl = this.message?.videoElem?.snapshotUrl;
|
||||
const key = md5(this.message?.videoElem?.videoUrl || '');
|
||||
this.coverCachePath = `_doc/${this.conversationID}/cover_${key}.jpg`;
|
||||
this.videoCachePath = `_doc/${this.conversationID}/${key}.mp4`;
|
||||
const coverExists = await util.fileExsit(this.coverCachePath);
|
||||
|
||||
// 自动缓存封面到 this.coverCachePath
|
||||
const self = this;
|
||||
if (typeof plus === 'undefined' || !this.coverCachePath) return;
|
||||
try {
|
||||
// 检查封面是否存在
|
||||
const coverExists = await util.fileExsit(self.coverCachePath);
|
||||
this.coverExists = !!coverExists;
|
||||
// 同时检查视频缓存是否存在
|
||||
const vidExists = await util.fileExsit(self.videoCachePath);
|
||||
this.videoExists = !!vidExists;
|
||||
if (this.coverExists) {
|
||||
this.src = this.coverCachePath;
|
||||
return;
|
||||
}
|
||||
if (!snapshotUrl) {
|
||||
this.src="/static/images/sync_error.png";
|
||||
return;
|
||||
}
|
||||
this.coverDownloading = true;
|
||||
await new Promise((resolve, reject) => {
|
||||
util.downloadFile(snapshotUrl, self.coverCachePath, function(localPath) {
|
||||
self.coverDownloading = false;
|
||||
self.coverExists = true;
|
||||
resolve(localPath);
|
||||
}, function(err) {
|
||||
self.coverDownloading = false;
|
||||
reject(err);
|
||||
}, function(progress) {
|
||||
self.coverDownloadProgress = progress;
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
this.coverDownloading = false;
|
||||
}
|
||||
const coverCachePath = `${this.conversationID}/cover_${key}.jpg`;
|
||||
this.videoCachePath = `${this.conversationID}/${key}.mp4`;
|
||||
this.videoExists = await util.fileExists(this.videoCachePath);
|
||||
self.coverDownloading = true;
|
||||
util.cacheFile(snapshotUrl,coverCachePath,(e)=>{
|
||||
self.coverDownloading = false;
|
||||
self.src = coverCachePath;
|
||||
console.log(e);
|
||||
},(e)=>{
|
||||
console.log(e);
|
||||
},(e)=>{
|
||||
console.log(e);
|
||||
});
|
||||
},
|
||||
clickMediaItem() {
|
||||
uni.previewImage({
|
||||
@@ -173,7 +146,7 @@
|
||||
onOverlayClick() {
|
||||
// 点击覆盖层:如果视频已缓存则直接播放,否则开始下载
|
||||
if (this.videoExists) {
|
||||
this.playVideo(this.videoCachePath);
|
||||
this.playVideo("_doc/"+this.videoCachePath);
|
||||
return;
|
||||
}
|
||||
const url = this.message?.videoElem?.videoUrl || this.message?.videoElem?.videoPath;
|
||||
@@ -186,7 +159,7 @@
|
||||
util.downloadFile(url, this.videoCachePath, (localPath) => {
|
||||
this.videoDownloading = false;
|
||||
this.videoExists = true;
|
||||
this.playVideo(localPath);
|
||||
this.playVideo("_doc/"+localPath);
|
||||
}, (err) => {
|
||||
this.videoDownloading = false;
|
||||
uni.showToast({ title: '下载失败' });
|
||||
|
||||
Reference in New Issue
Block a user