Created
March 26, 2014 18:01
-
-
Save xcoderzach/9789444 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener("deviceready", onDeviceReady, false); | |
function onDeviceReady(){ | |
console.log('onDeviceReady()'); | |
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, function() { console.log('FAIL - window.requestFileSystem'); } ); | |
} | |
// var mediaEncoded; | |
function gotFS (fileSystem) { | |
console.log("GotFS()"); | |
console.dir(fileSystem.root) | |
var fileName = "test" + Math.random() + ".wav" | |
console.log(fileName) | |
fileSystem.root.getFile(fileName, | |
{ create: true, exclusive: false }, //create if it does not exist | |
function success(entry) { | |
var mediaRec = new Media(entry.toURL(), function () { console.log("media Success on word") } ); | |
$(document).ready(function(){ | |
$("#startAgain").click(function(){ window.location = "index.html" }); | |
$("#wavPath").html("<strong>File created - ready to record at: </strong>"+entry.fullPath+"<br>"); | |
$("#record").click(function(){ | |
mediaRec.startRecord(); | |
$("#stop").click(function(){ | |
mediaRec.stopRecord(); | |
entry.file(function(file) { $("#before").html("<strong>wav size: </strong>"+file.size) }, function(error) { alert("Unable to retrieve file properties: " + error.code) }); | |
$("#play").click(function(){ mediaRec.play() }); | |
$("#encode").click(function(){ | |
var mediaEncoded; | |
var nativeURL = entry.toNativeURL().replace('file://', '') | |
window.encodeAudio( | |
nativeURL, | |
function(encodedFileSrc) { | |
console.log(encodedFileSrc) | |
mediaEncoded = new Media(encodedFileSrc, function () { console.log("media Success on word") } ); | |
$("#m4aPath").html("<strong>Encoded Recording File Path: </strong>"+encodedFileSrc); | |
fileSystem.root.getFile(encodedFileSrc, { create: false }, function(encodedEntry){ | |
encodedEntry.file(function(file) { $("#after").html("<strong>m4a size: </strong>"+file.size) }, function(error) { alert("Unable to retrieve file properties: " + error.code) }); | |
}, function () { console.log("could not get encoded audio file") }); | |
// You can pass this into a FT upload like this | |
// var ft = new FileTransfer(); | |
// ft.upload(encodedFileSrc, encodeURI("remoteDirectory including /"), uploadSuccess, uploadFail, options); | |
}, | |
function(statusCode){ alert("Encode Failed: "+statusCode) } | |
); | |
$("#playEncoded").click(function(){ mediaEncoded.play() }); | |
}); | |
}); | |
}); | |
}); | |
}, | |
function () { console.log("could not create audio file") } | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment