windows 8 - CameraCaptureUI.captureFileAsync fails to return IAsyncOperation object -


for reason, code unable retrieve iasyncoperation object returned upon calling capturefileasync method of windows.media.capture.cameracaptureui() method. iasyncoperation object returned according this documentation. in documentation link, states:

return value type: iasyncoperation<storagefile> when operationcompletes, storagefile object returned. 

so here code:

var dialog = new windows.media.capture.cameracaptureui(); var aspectratio = { width: 4, height: 3 };  dialog.photosettings.croppedaspectratio = aspectratio; appsession.inasyncmode = dialog.capturefileasync(windows.media.capture.cameracaptureuimode.photo).done(function (file) {         if (file) {             self.addpage(url.createobjecturl(file));         } else {             winjs.log && winjs.log("no photo captured.", "sample", "status");         }     }, function (err) {             // none taken     }); 

when inspect value of appsession.inaysncmode, see function returns undefined. suspect returns undefined because operation not complete (i.e. user has not yet created photo, , has not been saved disc), need in order cancel out of camera capture mode programmatically. know why return undefined instead of documented iasyncoperation object?

thanks!

for reference, here's answer posted on msdn forum.

to answer ending question, can cancel capture ui canceling promise dialog.capturefileasync.

your inasyncmode flag undefined because you're assigning return value capturefileasync.done() is, definition, undefined. has nothing api's success.

in docs, when see iasyncoperation, in javascript promise deliver result completed handler if succeed. never see iasyncoperation or related interfaces in javascript directly. documentation winrt written language-neutral, it's important understand how things show in js (as promises). in c# don't see either, use await keyword. it's in c++ encounter interface.

anyway, believe want along lines of code below, eliminate isasyncmode in favor of checking non-null promise:

appsession.capturepromise = dialog.capturefileasync(windows.media.capture.cameracaptureuimode.photo); appsession.isasyncmode = (appsession.capturepromise != null);   //this close capture ui after 5 seconds--replace whatever logic need settimeout(function () { appsession.capturepromise.cancel(); }, 5000);  appsession.capturepromise.done(function (file) {     if (file) {     } else {     } }, function (err) {     appsession.isasyncmode = false;     appsession.capturepromise = null; }); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -