我需要将下载的文件保存在我的 ionic 2 路径中并使用那个固定的 url 路径。 下载:使用文件传输插件。
const fileTransfer = new Transfer();
fileTransfer.download(trackObj.remoteUrl,cordova.file.dataDirectory+"audio/"+filename).then((entry)=>{
console.log("download completed:"+entry.toURL());
});
entry.toURL() 给出了类似 file://...... 的路径,需要使用该路径来使用媒体插件播放。但是,媒体插件不接受带有 file://... 的路径,
this.playerStatic = new MediaPlugin(internalFilePath,onStatusPlayerUpdate);
所以使用“cdvfile://localhost/library-nosync/”+ fileSrc;作为临时解决方案。它不适用于安卓。
所以为了能够在两个平台上使用,我应该能够遵循其他解决方案,其中路径将解析为 InternalURL。当我尝试
window.resolveLocalFileSystemURL(src, function(dir){});
它说 resolveLocalFileSystemURL 不是函数。 有人可以帮我吗?如何在 ionic 2 中使用 window.resolveLocalFileSystemURL?
最佳答案
我在 ionic 3 中使用它,用于 iOS 构建。请检查代码:
this.file.resolveLocalFilesystemUrl(this.file.dataDirectory).then((entry) => {
console.log("Success! Got a DirectoryEntry",entry);
});
在这里,我使用的是 cordova-plugin-file,但我认为它也适用于 cordova-plugin-file-transfer。如果有任何问题,请尝试让我知道。
关于android - ionic 2 中的 window.resolveLocalFilesystemUrl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41791843/