我有2个智能手机将音频文件保存在不同的文件夹中,一个在根目录中,另一个在根目录/音频文件夹中。我想要做的是,每当captureAudio成功时,我都不想将它保存到默认文件夹(音频或root)。我想创建一个名为Test(example)的文件夹,并根据我的需要重命名音频文件。这是我到目前为止所得到的,并且给出了关于[Object] [Object]没有方法moveTo的错误;
function captureAudio() {
// Launch device audio recording application, allowing user to capture up to 2 audio clips
navigator.device.capture.captureAudio(captureSuccess, fail, {limit: 1});
}
function captureSuccess(mediaFiles) {
var d = new Date();
var n = d.getTime();
var entry = mediaFiles.fullPath;
var file = code + "_" + n + ".m4a";
var folder = "Test";
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
function (fileSys) {
fileSys.root.getDirectory(folder, {create: true, exclusive: false},
function (directory) {
entry.moveTo(directory, file,
success, fail);
}, fail);
}, fail);
}
答案 0 :(得分:2)
不知怎的,我做到了,
var captureSuccess = function (mediaFiles) {
// SystemURI require string and path2 will deal it and must not use file:/(path)
var path = mediaFiles[0].fullPath;
var path2 = path.slice(0, 5) + "//" + path.slice(5);
window.resolveLocalFileSystemURI(path2, successMoveTo, fail);
}
function successMoveTo(entry) {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
function (fileSys) {
fileSys.root.getDirectory(folder, {create: true, exclusive: false},
function (directory) {
entry.moveTo(directory, file,
success, fail);
}, fail);
}, fail);
}