Ionic - 从使用 cordova 插件媒体录制的音频中获取文件

Ionic - Get file from audio recorded with cordova plugin media

我将 ionic 与 cordova-plugin-media to record audio and i want upload the audio recorded to server using 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”,“文档:/ /recorded.wav" 但每次都是同样的错误...

有人知道我怎样才能得到这个文件吗?

最后我使用 cordova 插件 (cordova-file-transfer) 来获取我使用的文件:

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

我希望这对某人有帮助,我在这个 sh*t 上浪费了很多时间。