这段代码在iOS上运行得很好,在安卓设备上似乎也运行得很好,但是在检查数据库时,所有在安卓手机上录制的录音最终都会出现在数据库上,大小为0kb,不会播放。所以他们堕落了什么的..。
var options = { limit: 1, duration: 10 };
console.log(options);
$cordovaCapture.captureAudio(options).then(function(audioData)
{
// alert("Record was success");
console.log("in $cordovaCapture.captureAudio function")
var path = audioData[0].fullPath;
console.log(path + " var path")
window.localStorage['tmpRecord'] = path;
console.log(window.localStorage['tmpRecord'] + " window.localStorage")
window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, gotFS, fail);
function gotFS(fileSystem) {
console.log(fileSystem + " gotFS function");
fileSystem.root.getFile(audioData[0].name, {create : true}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
console.log("gotFileEntry:" + fileEntry);
fileEntry.file(gotFile, fail);
}
function gotFile(file){
console.log("gotFile");
//readBinaryString(file);
readArrayBuffer(file);
}
/* GET TIMESTAMP */
function checkTime(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
function getHHMMSS(){
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
// add a zero in front of numbers<10
m = checkTime(m);
s = checkTime(s);
return h + ":" + m + ":" + s;
}
/************* SAVE THE FILE *************/
function readArrayBuffer(file){
var reader = new FileReader();
console.log(reader + " var reader is here");
reader.onloadend = function(evt) {
console.log("readArrayBuffer : " + evt.target.result);
var ParseFile = new Parse.File("recording.wav", file);
console.log(ParseFile + " var Parsefile is here")
ParseFile.save().then(function()
{
// alert('Inside ParseFile.save()');
var myPoint = new Parse.GeoPoint({latitude: $scope.currentLiveLatitude, longitude: $scope.currentLiveLongitude});
console.log(myPoint)
var recording = new Parse.Object("Recordings");
console.log(recording)
/*Set variables */
recording.set("username", "Sasstic Plurgery");
recording.set("latitude", $scope.currentLiveLatitude.toString());
recording.set("longitude", $scope.currentLiveLongitude.toString());
recording.set("geoLocation", myPoint);
recording.set("dateTime", getHHMMSS());
recording.set("recording", ParseFile);
/*Save to server */
recording.save({
success: function(recording) {
alert("Recordings saved successfully");
},
error: function(recording, error){
alert("Recordings save failure, error = " + error + " error msg: " + error.message);
}
});
},function(error) {
alert("File save failure");
});
}
reader.readAsArrayBuffer(file);
}
这里发生了什么事?我搜索了又搜索,没有找到任何答案。谷歌至少搜索了3页,还有几个不同的查询。
UPDATE -所以我想出了如何使用下面的代码来检查文件是否存在:
function checkIfFileExists(path){
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){
fileSystem.root.getFile(path, { create: false }, fileExists, fileDoesNotExist);
}, getFSFail); //of requestFileSystem
}
function fileExists(fileEntry){
alert("File " + fileEntry.fullPath + " exists!");
}
function fileDoesNotExist(){
alert("file does not exist");
}
function getFSFail(evt) {
console.log(evt.target.error.code);
}
checkIfFileExists(audioData[0].name);
结果却是假的。所以这个文件是由Android创建的,但是它应该不存在于文件系统中,这是令人困惑的,因为audioData.fullPath中的文件路径似乎是正确的,因为我可以在声音目录下看到一个名为Android的文件。
我想出的另一个解释是,离子运行android -l的livereload调试模式应该使用计算机来托管所有文件,而只是使用该设备作为接口。所以也许这和它有关--但是当我做一个普通的离子构建和离子或cordova运行时,我在上传的文件中得到了同样的错误。
现在,解决方案似乎是找出默认的语音记录器保存其文件的位置,并指导引用该文件的路径。
发布于 2015-05-05 04:23:15
解决了这个问题-- {create: true}参数导致了文件的生成,从而生成了一个0 kb的文件。但还是有问题的。必须弄清楚如何从应用程序的fileSystem根目录到几个目录,然后返回到/Sounds文件夹,默认的语音记录器存储它的东西。除非有另一个插件可以为我们做录音。
https://stackoverflow.com/questions/29954367
复制相似问题