在我的应用程序中需要从移动设备上传音频文件(iPhone/Android)。音频文件是通话录音。

即使用户使用不同的呼叫记录器应用程序,我能找到呼叫记录文件的路径吗?我在路径中寻找音频文件:“/private/var/mobile/Media/Containers/Data/Application”和 cordova.file.tempDirectory,我不确定路径是否正确?

我尝试在代码下面的 requestFileSystem 中执行此操作:

var numDirs = 0;
var numFiles = 0;
var ImageFilePath = new Array();

function GetAllAudioFromSD11() {
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail);

}

function onFileSystemSuccess(fileSystem) {
    fileSystem.root.getDirectory("/private/var/mobile/Media/Containers/Data/Application", { create: false, exclusive: false }, getDirSuccess, fail);
}

function getDirSuccess(dirEntry) {
    var directoryReader = dirEntry.createReader();

    // Get a list of all the entries in the directory
    directoryReader.readEntries(readerSuccess, fail);
}

var readerTimeout = null, millisecondsBetweenReadSuccess = 1000;

function readerSuccess(entries) {
    String.prototype.startsWith = function (str)
    { return (this.match("^" + str) == str) }

    var i = 0, len = entries.length;
    for (; i < len; i++) {
        if (entries[i].isFile) {
            if ((entries[i].name.indexOf(".wav") != -1) || (entries[i].name.indexOf(".mp3") != -1) || (entries[i].name.indexOf(".amr") != -1)) {
                var fileName = entries[i].name;
                if (!fileName.startsWith(".")) {
                    numFiles++;
                    ImageFilePath.push(entries[i].fullPath)
                    //  console.log("file "+entries[i].fullPath)
                }
            }

        } else if (entries[i].isDirectory) {
            numDirs++;
            // console.log("directory "+entries[i].name)
            var dirName = entries[i].name;
            if (!dirName.startsWith(".")) {
                getDirSuccess(entries[i]);
            }
        }
        if (readerTimeout) {
            window.clearTimeout(readerTimeout);
        }
    }
    if (readerTimeout) {
        window.clearTimeout(readerTimeout);
    }
    readerTimeout = window.setTimeout(weAreDone, millisecondsBetweenReadSuccess);

}

另外尝试文件 opneer2 插件

function GetAllAudioFromSD()
    {
    cordova.plugins.fileOpener2.open(
    '/private/var/mobile/Media/Containers/Data/Application', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf
    'application/pdf', 
    { 
        error : function(e) { 
            console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
        },
        success : function () {
            console.log('file opened successfully'); 
        }
    }
);

    }

使用这些解决方案,我可以上传图片和视频,但我看不到音频文件来选择它并上传它。