2016-01-21 49 views
1

我使用离子与cordova-plugin-media录制音频,我想上传音频录制到服务器使用angular-file-upload但我不知道如何从媒体中获取文件。我只是试试这个:离子 - 从音频获取文件与科尔多瓦插件媒体记录

控制器:

$scope.itemOnLongPress = function (id) {; 
      myMedia = new Media("./sound/recorded.wav"); 
      myMedia.startRecord(); 
} 

$scope.itemOnTouchEnd = function (id) { 
    myMedia.stopRecord(); 
    myMedia.play(); 
    window.resolveLocalFileSystemURI(myMedia.src, 
     // success callback; generates the FileEntry object needed to convert to Base64 string 
     function (fileEntry) { 
      // convert to Base64 string 
      function win(file) { 
       var reader = new FileReader(); 
       reader.onloadend = function (evt) { 
        var obj = evt.target.result; // this is your Base64 string 
        alert(obj); 
       }; 
       reader.readAsDataURL(file); 
      }; 
      var fail = function (evt) {}; 
      fileEntry.file(win, fail); 
     }, 
     // error callback 
     function() { 
      alert('fail'); 
     } 
    ); 

所有时间我收到“失败”,从事件,我尝试使用一些前缀,如:“/sdcard/recorded.wav","file:/// sound/recorded.wav“,”documents://recorded.wav“,但每次出现同样的错误...

任何人都知道我可以得到这个文件吗?

回答

5

最后我用科尔多瓦插件(科尔多瓦文件传输),为做到这一点,并获得文件我使用:

window.requestFileSystem(LocalFileSystem.TEMPORARY,0,function(filesystem) { 
    var file = filesystem.root.toUrl; 
    /*and need remove file:// from path so..*/ 
    file = file.slice(7) 
} 

我希望这可以帮助别人,我浪费了很多时间,这个上海*吨。

相关问题