用于Cordova Android项目的窗口resolveLocalFileSystemURL上的TypeError

时间:2018-06-13 04:53:53

标签: javascript android cordova filesystems

我正在使用Cordova框架处理音乐流媒体应用程序,播放存储在GoogleCloudStorage上的音乐,我有一个按钮,onClick将应用程序根目录文件夹中的设备外部存储设备保存为歌曲“com.strma.strma”< / strong>即可。我的第一次编译功能完美,它将mp3保存到设备存储中,但我现在在控制台中收到此错误:

“Preparing.js:64 Uncaught(in promise)TypeError:无法读取window.resolveLocalFileSystemURL的属性'trim'(Preparing.js:at save4dev.js:39” < /强>

这是我保存歌曲的代码,它是承诺的一部分,首先将歌曲添加到用户firebase数据库,然后()将歌曲下载到App根文件夹;

.then(function(){
                var songName = libContents.songName;
                var file_url;
               // a. request filesystem for app
                    resolveLocalFileSystemURL(cordova.file.externalApplicationStorageDirectory, function (dirEntry) {
                        console.log(dirEntry.name)
                        // i. Get url of song
                        var storageRef = firebase.storage().ref().child("songsAll/"+songName );

                        storageRef.getDownloadURL().then(function(url) {
                            file_url = url;
                        })
                        // ii. Add to XHR constructor
                        .then(function(){
                            // 1. xhr function

                                var xhr = new XMLHttpRequest();
                                xhr.open(`GET`,file_url,true);
                                xhr.responseType  = `blob`;                                
                                xhr.onreadystatechange  = function(){

                                    if( xhr.readyState ==4 && xhr.status == 200){
                                        songName = libContents.songName;

                                        var blob = xhr.response;
                                        createFile(dirEntry, songName, blob)
                                    }
                                }  
                                xhr.send();
                            // 2. savefile function
                            function createFile(dirEntry, songName, blob){
                                var isAppend = true;
                                dirEntry.getFile(songName, {create:true, exclusive:false}, function(fileEntry){
                                    writeFile(fileEntry,blob, isAppend)
                                })
                            }
                            // 3. Write file Function
                            function writeFile(fileEntry,blob, isAppend){
                                fileEntry.createWriter(function(fileWriter){
                                    fileWriter.write(blob)
                                })
                            }
                        })
                },function(){})
            })

我还打开了“Preparing.js”文件,这是突出显示的错误。Image of Prepare.js code。我该如何解决这个问题?

0 个答案:

没有答案