【问题标题】:window.resolveLocalFilesystemUrl in ionic 2离子2中的window.resolveLocalFilesystemUrl
【发布时间】:2017-01-22 14:04:24
【问题描述】:

我需要将下载的文件保存在我的 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://...... 的路径,需要使用该路径来使用 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;作为临时解决方案。它不适用于安卓。

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

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

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

【问题讨论】:

  • 只需从该路径中删除 file://。
  • 我很好奇,但是将 remoteUrl 提供给 mediaplugin 不会起作用吗?
  • mediaplugin 可以工作,但我想下载并使用它以备后用
  • 尝试删除 file://。没运气。得到:错误:未处理的承诺拒绝:[object Object];区域: ;任务: ;值:[对象对象]。所以尝试通过硬编码 iOS 的路径来获取 cdvfile:// url。但是有人可以提出更好的方法吗?
  • 我认为 File 上有一个 toInternalURL() 方法

标签: android ionic2 cordova-plugins


【解决方案1】:

我在 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。如果有任何问题,请尝试告诉我。

【讨论】:

    猜你喜欢
    • 2017-09-27
    • 1970-01-01
    • 2017-01-19
    • 1970-01-01
    • 2016-09-30
    • 1970-01-01
    • 2016-12-27
    • 2018-04-23
    • 1970-01-01
    相关资源
    最近更新 更多