Cordova:在iOS中存储录制的音频文件的正确位置是什么?

时间:2016-03-09 01:53:25

标签: ios cordova audio media phonegap-build

我正在使用媒体插件录制声音。

var my_media = new Media('test.wav');
my_media.startRecord();
my_media.stopRecord() // after few seconds
my_media.release();
my_media.play();//works fine


// But when I try to Check if test.wav file exist I always get false as status.


//File name of our important data file we didn't ship with the app
var fileName = "test.wav";

function init() {

console.log("Checking for data file.");

//Check for the file. 
window.resolveLocalFileSystemURL(fileName, onSuccess, onFail);

}

function onSuccess() {
console.log("Great! This file exists");
 }

function onFail() {
console.log('Sorry! File not Found');
}

// I always get this message: Sorry! File not Found

这样做的正确方法是什么?录制后我希望用户能够看到可用录制声音的列表,用户应该可以播放它。为此,我需要检查文件是否存在。 那么我们应该如何实现呢?

1 个答案:

答案 0 :(得分:1)

您可以将录制的文件列表显示为:

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
    fileSystem.root.getDirectory(YOUR_PATH, {
        create: true
    }, function(directory) {
        root_path = fileSystem.root.toURL();
        var directoryReader = directory.createReader();
        directoryReader.readEntries(function(entries) {
            var i;
            for (i = 0; i < entries.length; i++) {
                //Get file URL as: entries[i].toURL()); & display using creating dynamic tag.
            }
        }, function(error) {
            alert(error.code);
        });

    });
}, function(error) {
    alert("can't even get the file system: " + error.code);
});