离子2中的window.resolveLocalFilesystemUrl

时间:2017-01-22 14:04:25

标签: android ionic2 cordova-plugins

我需要在我的离子2路径中保存下载的文件并使用该ineteral 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:// ......这样的路径,需要使用该路径来播放使用Media插件。但是,Media插件不接受带有file:// ...,

的路径
this.playerStatic = new MediaPlugin(internalFilePath,onStatusPlayerUpdate);

所以,谷歌搜索发现:https://forum.ionicframework.com/t/ios-9-cant-play-audio-video-files-that-are-downloaded-to-device/37580/4

所以使用" cdvfile:// localhost / library-nosync /" + fileSrc;作为临时解决方案。它不适用于Android。

因此,为了能够在两个平台上使用,我应该能够遵循其他解决方案,其中路径将被解析为InternalURL。当我尝试

window.resolveLocalFileSystemURL(src, function(dir){});

它的说法resolveLocalFileSystemURL不是一个函数。 有人可以帮我吗?如何在离子2中使用window.resolveLocalFileSystemURL?

1 个答案:

答案 0 :(得分:1)

我在离子3中使用它,用于iOS构建。请检查代码:

auto_prepend_file

在这里,我使用的是cordova-plugin-file,但我认为它也适用于cordova-plugin-file-transfer。如果有任何问题,请尝试告诉我。