1 Reply Latest reply on Mar 11, 2018 11:19 AM by emilianos1725396

    downloading wav file and then playing with media on iOS and desktop app


      I've been pulling my hair on this simple thing. (or should be)


      I am trying to play a downloaded wav file.  The download part works, apparently.  But the playing part is not.


      This is how I do it:


      function fail(error){

           alert("failed "+error);



      //this is how i download the file:

      function downloadFile(fileSystem, url, filename, callback, callback_error) {

        var fileTransfer = new FileTransfer();


           fileSystem.root.toURL() + filename,

           function (theFile) {

                console.log("download complete: " + theFile.toURL());

                if (callback)



           function (error) {

                console.log("download error source " + error.source);

                console.log("download error target " + error.target);

                console.log("upload error code: " + error.code);

                if (callback_error)






      function onfileSystemFailWav(evt) {




      //this is the callback when the file was downloaded succesfully, it will play it.  This is what isn't working (the callback is getting called though)

      function downloadedwav(aURI){

           var my_media = new Media(aURI,

                       // success callback

                        function () { console.log("playAudio():Audio Success"); },

                       // error callback

                        function (err) { console.log("playAudio():Audio Error: " + err); }


                 // Play audio




      function downloadwaverror(error){

           alert("error downloading: "+error);




      function downloadFileAndPlay(aURL,aFileName) {

         window.requestFileSystem(LocalFileSystem.TEMPORARY, 0,

              function (fileSystem) {

                 downloadFile(fileSystem, aURL, aFileName, downloadedwav, downloadwaverror);


             , onfileSystemFailWav







      So, when using this downloadFileAndPlay function, the download is successful,  but the media results in this error:  playAudio():Audio Error: [object Object]


      after the download, the  .toURL() function returns:

                 file:///var/mobile/Containers/Data/Application/08CB83B3-EB09-4B99-9950-B381E0396751/tmp/2 -1519319709.wav



      what am i missing.   I've tried many other ways to do this, ended up with some error with media playing that file. Maybe the plug in cannot access the temporary filesystem?  what is it? I tried playing the same wav locally without downloading it, from the www folder of phonegap locally and it played perfectly. the problem seems to be related to the filesystem access of the media plugin.  How can i make it work? i'm in a hurry on this because obviously, when planning, I assumed that this was a trivial thing to code.