【发布时间】:2017-04-18 18:22:08
【问题描述】:
在我的 Ionic 2 应用程序中,我使用此功能下载视频文件并跟踪其下载进度:
download()
{
this.progressbar=true;
this.downloadbutton=false;
this.fileTransfer.download('https://...videoURL....mp4', this.file.dataDirectory + 'path/to/downloads/test.mp4').then((entry) => {
console.log('download complete: ' + entry.toURL());
this.progressbar=false;
this.startbutton=true;
}, (error) => {
console.log('error');
console.log(error);
});
this.fileTransfer.onProgress(progressEvent => {
if (progressEvent.lengthComputable) {
console.log("### Download percentage ###: "+Math.round((progressEvent.loaded / progressEvent.total)*100));
this.setpercentage((progressEvent.loaded / progressEvent.total) * 100);
} else {
}
});
}
使用setpercentage,我更新页面上的进度条
setpercentage(perc) {
this.loadProgress = Math.round(perc);
this.ref.detectChanges();
}
这一切都很好。当用户离开(返回)时,视图被销毁。视频继续下载(应该如此),但是当我导航回页面时(视频仍在下载时),进度条没有更新:值保持在 0%。
即使视图被破坏,我怎样才能保持进度条更新?
基本上,我想让这个page 具有与tab 相同的功能。当用户在不同的选项卡之间导航时,前一个选项卡的所有内容都会被记住。
非常感谢任何帮助!
更新:
以下是应用程序如何工作的更多信息:
当用户第一次导航到该页面时,会有一个显示“下载电影”的按钮。当用户点击它时,download() 被调用。 this.progressbar=true; 使进度条出现,而this.downloadbutton=false 使下载按钮消失。下载完成后,进度条消失 (this.progressbar=false;) 并出现“播放电影”按钮 (this.startbutton=true;)。 问题是当用户单击下载按钮,然后导航离开并返回此页面时,似乎一切都已重置(尽管电影确实下载了),并且下载按钮是再次显示。
【问题讨论】:
标签: angular ionic-framework ionic2