You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ti...@apache.org on 2012/06/27 20:43:16 UTC
[3/3] js commit: [CB-117]Added captureAudio for playbook
[CB-117]Added captureAudio for playbook
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/f00ef01b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/f00ef01b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/f00ef01b
Branch: refs/heads/master
Commit: f00ef01b6b22cba5ce5c45dddbe7b085700cb531
Parents: b9f2fe0
Author: Tim Kim <ti...@nitobi.com>
Authored: Thu Jun 14 17:18:02 2012 -0700
Committer: Tim Kim <ti...@nitobi.com>
Committed: Wed Jun 27 11:40:24 2012 -0700
----------------------------------------------------------------------
lib/playbook/plugin/playbook/capture.js | 37 +++++++++++++++++++++++++-
1 files changed, 36 insertions(+), 1 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/f00ef01b/lib/playbook/plugin/playbook/capture.js
----------------------------------------------------------------------
diff --git a/lib/playbook/plugin/playbook/capture.js b/lib/playbook/plugin/playbook/capture.js
index 64697f6..eb9b63e 100644
--- a/lib/playbook/plugin/playbook/capture.js
+++ b/lib/playbook/plugin/playbook/capture.js
@@ -35,6 +35,7 @@ module.exports = {
return {"status": cordova.callbackStatus.OK, "message": []};
},
captureImage: function (args, win, fail) {
+ console.log('pic');
if (args[0].limit > 0) {
capture("takePicture", win, fail);
}
@@ -55,6 +56,40 @@ module.exports = {
return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On It" };
},
captureAudio: function (args, win, fail) {
- return {"status": cordova.callbackStatus.INVALID_ACTION, "message": "captureAudio is not currently supported"};
+ var onCaptureAudioWin = function(filePath){
+ // for some reason the filePath is coming back as a string between two double quotes
+ filePath = filePath.slice(1, filePath.length-1);
+ var file = blackberry.io.file.getFileProperties(filePath);
+
+ win([{
+ fullPath: filePath,
+ lastModifiedDate: file.dateModified,
+ name: filePath.replace(file.directory + "/", ""),
+ size: file.size,
+ type: file.fileExtension
+ }]);
+ }
+
+ var onCaptureAudioFail = function(){
+ fail([]);
+ }
+
+ if (args[0].limit > 0 && args[0].duration){
+
+ // a sloppy way of creating a uuid since there's no built in date function to get milliseconds since epoch
+ // might be better to instead check files within directory and then figure out the next file name shoud be
+ // ie, img000 -> img001 though that would take awhile and would add a whole bunch of checks
+ var id = new Date();
+ id = (id.getDay()).toString() + (id.getHours()).toString() + (id.getSeconds()).toString() + (id.getMilliseconds()).toString() + (id.getYear()).toString();
+
+ var fileName = blackberry.io.dir.appDirs.shared.music.path+'/audio'+id+'.wav';
+ blackberry.media.microphone.record(fileName, onCaptureAudioWin, onCaptureAudioFail);
+ // multiple duration by a 1000 since it comes in as seconds
+ setTimeout(blackberry.media.microphone.stop,args[0].duration*1000);
+ }
+ else {
+ win([]);
+ }
+ return {"status": cordova.callbackStatus.NO_RESULT, "message": "WebWorks Is On It"};
}
};