1
我現在的應用程序非常簡單。它會記錄一個音頻文件。我想要在phonegap API中使用readAsDataURL()
將音頻文件轉換爲base64字符串。以下是我的代碼如下。正如你所看到的,我遵循documentation獲取下面的base64字符串。在下面的代碼中,我試圖獲取base64字符串並將其存儲在變量中,然後使用該變量在當前的警告框中顯示該字符串。截至目前,我只能獲得「數據:音頻/波形; base64」,現在我已經堅持了4周。我真的很感謝一些幫助。如何使用Phonegap將音頻文件轉換爲iOS上的base64字符串?
function gotFS(fileSystem) {
fileSystem.root.getFile("myaudio.wav", {create: true, exclusive: false}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.file(gotFile, fail);
}
function gotFile(file){
readDataUrl(file);
}
function readDataUrl(file) {
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log("read success");
console.log(evt.target.result);
var thed = evt.target.result;
alert(thed); //trying to display the base64 string in an alert box
};
reader.readAsDataURL(file);
}