Lim Samantha
Posts: 0
Joined: Wed Jun 11, 2014 6:50 am

Audio Recorder

hi these are my codes:

function captureSuccess(mediaFiles) {
var i, len;
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
function win(r) {
alert("Code = " + r.responseCode);
alert("Response = " + r.response);
alert("Sent = " + r.bytesSent);
}
function fail(error) {
alert("An error has occurred: Code = " + error.code);
alert("upload error source " + error.source);
alert("upload error target " + error.target);
}
var fileURI = data.imageURI;
var headers = {
'X-Appery-Database-Id': 'XXXXXXXXXXXXXXXX',
'X-Appery-Session-Token': localStorage.getItem("userSessionToken")
};
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = fileURI.substr(fileURI.lastIndexOf('/') + 1);
options.mimeType = 'image/jpeg';
options.headers = headers;
var uri = encodeURI("https://api.appery.io/rest/1/db/files/" + options.fileName);
var ft = new FileTransfer();
ft.upload(fileURI, uri, win, fail, options);
}
}

Code: Select all

 // Called if something bad happens. 
 // 
 function captureError(error) { 
     var msg = 'An error occurred during capture: ' + error.code; 
     navigator.notification.alert(msg, null, 'Uh oh!'); 
 } 

 // A button will call this function 
 // 
 function captureImage() { 
     // Launch device camera application, 
     // allowing user to capture up to 2 images 
     navigator.device.capture.captureImage(captureSuccess, captureError, {limit: 2}); 
 } 

 // Upload files to server 
 function uploadFile(mediaFile) { 
     var ft = new FileTransfer(), 
         path = mediaFile.fullPath, 
         name = mediaFile.name; 

     ft.upload(path, 
         "[url=http://my.domain.com/upload.php]http://my.domain.com/upload.php[/url]", 
         function(result) { 
             console.log('Upload success: ' + result.responseCode); 
             console.log(result.bytesSent + ' bytes sent'); 
         }, 
         function(error) { 
             console.log('Error uploading file ' + path + ': ' + error.code); 
         }, 
         { fileName: name }); 
 } 

captureImage();

i run javascript on button click
no mapping though.

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Audio Recorder

Hello Lim,

On click on the button you should call this code:

code
function captureSuccess(mediaFiles) {
var i, len;
for (i = 0, len = mediaFiles&#46;length; i < len; i += 1) {
uploadFile(mediaFiles);
}
}

&#47;&#47; Called if something bad happens&#46;
&#47;&#47;
function captureError(error) {
var msg = 'An error occurred during capture: ' + error&#46;code;
navigator&#46;notification&#46;alert(msg, null, 'Uh oh!');
}

&#47;&#47; A button will call this function
&#47;&#47;
function captureAudio() {
&#47;&#47; Launch device audio recording application,
&#47;&#47; allowing user to capture up to 2 audio clips
navigator&#46;device&#46;capture&#46;captureAudio(captureSuccess, captureError, {limit: 2});
}

&#47;&#47; Upload files to server
function uploadFile(mediaFile) {
var ft = new FileTransfer(),
path = mediaFile&#46;fullPath,
name = mediaFile&#46;name;
var headers = {
'X-Appery-Database-Id': '530xxxxxxxxxe3176f4222e7',
'X-Appery-Session-Token': localStorage&#46;getItem("userSessionToken")
};
var options = new FileUploadOptions();
options&#46;fileKey = "file&quot
options&#46;fileName = name;

Code: Select all

 options&#46;headers = headers; 

 ft&#46;upload(path, 
     encodeURI("https:&#47;&#47;api&#46;appery&#46;io/rest/1/db/files/" + name), 
     function(result) { 
         console&#46;log('Upload success: ' + result&#46;responseCode); 
         console&#46;log(result&#46;bytesSent + ' bytes sent'); 
     }, 
     function(error) { 
         console&#46;log('Error uploading file ' + path + ': ' + error&#46;code); 
     }, 
               options); 

}
captureAudio();
/code

Please note that in the X-Appery-Database-Id must be specified the correct id of that database in Appery.io in which you will keep the files. Also the user should be logged in the application and his sessionToken should be saved in LSV userSessionToken.
Also please note that we provide you this code, those custom app logic and custom JS are outside the scope of our support.

Lim Samantha
Posts: 0
Joined: Wed Jun 11, 2014 6:50 am

Audio Recorder

Hi, thank you for all the help. I appreciate alot!
Thanks!

zaik
Posts: 0
Joined: Wed Sep 09, 2015 7:15 am

Audio Recorder

Hi Evenge. I have used this code to capture audio. I am getting this error?

Uh oh!
An error occurred during capture:
undefined

ok

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Audio Recorder

Zaik,

Please specify where do you get this error? Also please check for the errors in a browser console.

zaik
Posts: 0
Joined: Wed Sep 09, 2015 7:15 am

Audio Recorder

When I call event capture Audio and i am able to capture audio. But when i press back button i give me this error reported above,

zaik
Posts: 0
Joined: Wed Sep 09, 2015 7:15 am

Audio Recorder

How ca I play capture audio in my app. I able to get get full path and stored it in variable $scope.audPath. But when i call this path in Audio tag of my html like this {{audPath}} nthing plays at that time.

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Audio Recorder

Zaik,

Unfortunately we don't have ready solution for this case,and as soon as this is the custom js code and it will require the participation of the development team we can offer you purchasing Advisory Pack to get more in-depth help on this question. Here is more information about it: http://appery.io/services/#Advisory_Pack

CMWOO
Posts: 0
Joined: Tue Jan 26, 2016 4:01 am

Audio Recorder

Hello, did you solve your problem? Now i also get stunk on this part....

Return to “Issues”