2014-09-30 1 views
1

내 응용 프로그램은 매우 간단합니다. 오디오 파일을 녹음합니다. phonegap API에서 readAsDataURL()
을 사용하여 오디오 파일을 base64 문자열로 변환하고 싶습니다. 여기에 내 코드가있다. 보시다시피 아래 base64 문자열을 가져 오는 데는 documentation을 따르고 있습니다. 아래 코드에서 base64 문자열을 가져 와서 변수에 저장하고 그 변수를 사용하여 잠시 동안 경고 상자에 문자열을 표시하려고합니다. 현재로서는 "data : audio/wav, 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); 
} 

답변

0
document.addEventListener("deviceready", init, false); 
    function init() { 


     //This alias is a read-only pointer to the app itself 
     window.resolveLocalFileSystemURL(cordova.file.applicationDirectory + "www/button-1.mp3", gotFile, fail); 

     // var src = "/android_asset/www/sounds/button-1.mp3"; 

    } 

    function fail(e) { 
     // console.log("FileSystem Error"); 
     // console.dir(e); 
    } 

    function gotFile(fileEntry) { 

     fileEntry.file(function(file) { 
     var reader = new FileReader(); 

     reader.onloadend = function(e) { 
      console.log("Text is: "+this.result); 

     }; 

     // reader.readAsText(file); 
     // reader.readAsArrayBuffer(file); 
     // reader.readAsBinaryString(file); 
     reader.readAsDataURL(file); 
     }); 
관련 문제