locked
WinRTError unknown error when using creationcollisionoption

    Question

  • This works: Windows.Storage.ApplicationData.current.temporaryFolder.createFileAsync(photoFile)

    But this: Windows.Storage.ApplicationData.current.temporaryFolder.createFileAsync(photoFile, Windows.Storage.CreationCollisionOption.replaceExisting)
    throws an exception unknown error when passing the created file to mediaCaptureMgr.capturePhotoToStorageFileAsync

    Why is that?

    full code for reference:

    Windows.Storage.ApplicationData.current.temporaryFolder.createFileAsync(photoFile, Windows.Storage.CreationCollisionOption.replaceExisting).then(
            function (newFile) {
                photoStorage = newFile;
    
                var photoProperties = photoPoster.createDefaultImageEncodingProperties();
    
                mediaCaptureMgr.capturePhotoToStorageFileAsync(photoProperties, photoStorage).then(
                    function (result) {
                        // ...
                    },
                    function capturePhotoError(error) {
                        var exception = error; // threw unknown error!
                    }
                );
            },
            function (error) {
                var exception = error;
            }
        );

    R

    Thursday, May 10, 2012 6:10 PM

Answers

  • Hi R,

    I modified the "Media capture using webcam sample" and it works fine.  The code is ever so slightly different:

    function capturePhoto() {
            sdkSample.displayStatus("Taking photo");
            return Windows.Storage.ApplicationData.current.temporaryFolder.createFileAsync(photoFile, Windows.Storage.CreationCollisionOption.replaceExisting).then(
            function (newFile) {
                photoStorage = newFile;
                var photoProperties = new Windows.Media.MediaProperties.ImageEncodingProperties();
                photoProperties.subtype = "JPEG";
                photoProperties.width = 320;
                photoProperties.height = 240;

                mediaCaptureMgr.capturePhotoToStorageFileAsync(photoProperties, photoStorage).then(
                function (result) {
                    sdkSample.displayStatus("Photo Taken.  File " + photoStorage.path + "  ");
                    var url = URL.createObjectURL(photoStorage, false);
                    id("imageTag" + sdkSample.scenarioId).src = url;
                },
                function capturePhotoError(error) {
                    sdkSample.displayStatus("An exception occurred trying to capturePhoto: " + error.message);
                });
            },
            function (error) {
                sdkSample.displayStatus("capturePhoto async exception " + error.message);
            });
        }

    Give the sample a shot on your system with my modifications and let me know the result!

    -Jeff


    Jeff Sanders (MSFT)

    Thursday, May 10, 2012 7:22 PM
    Moderator
  • I met the same problem.

    Then I used Jeff's code verbatim, it works.

    When using my own code , I got the same error.

    My solution: 1. must define the width and height with the picture.

                        2. must invoke the method mediaCapture.initializeAsync(mediaCaputreSettings) before other methods.



    Friday, June 15, 2012 4:06 AM

All replies

  • Hi R,

    I modified the "Media capture using webcam sample" and it works fine.  The code is ever so slightly different:

    function capturePhoto() {
            sdkSample.displayStatus("Taking photo");
            return Windows.Storage.ApplicationData.current.temporaryFolder.createFileAsync(photoFile, Windows.Storage.CreationCollisionOption.replaceExisting).then(
            function (newFile) {
                photoStorage = newFile;
                var photoProperties = new Windows.Media.MediaProperties.ImageEncodingProperties();
                photoProperties.subtype = "JPEG";
                photoProperties.width = 320;
                photoProperties.height = 240;

                mediaCaptureMgr.capturePhotoToStorageFileAsync(photoProperties, photoStorage).then(
                function (result) {
                    sdkSample.displayStatus("Photo Taken.  File " + photoStorage.path + "  ");
                    var url = URL.createObjectURL(photoStorage, false);
                    id("imageTag" + sdkSample.scenarioId).src = url;
                },
                function capturePhotoError(error) {
                    sdkSample.displayStatus("An exception occurred trying to capturePhoto: " + error.message);
                });
            },
            function (error) {
                sdkSample.displayStatus("capturePhoto async exception " + error.message);
            });
        }

    Give the sample a shot on your system with my modifications and let me know the result!

    -Jeff


    Jeff Sanders (MSFT)

    Thursday, May 10, 2012 7:22 PM
    Moderator
  • strange.

    I made the same change on the "Media capture using webcam sample" and get the same error as in my project:

    "WinRTError: Unknown runtime error
       at completed (Function code:234:21)"

    'WWAHost.exe' (Script): Loaded 'Script Code (MSAppHost/1.0)'. 
    Exception was thrown at line 235, column 21 in Function code
    0xc00d36b2 - JavaScript runtime error: Unknown runtime error

    I'm running a Lenovo W510, Core i7, Windows 8 Consumer Preview booted from VHD

    Friday, May 11, 2012 7:53 PM
  • Did you use my code verbatim?

    -Jeff


    Jeff Sanders (MSFT)

    Friday, May 11, 2012 7:55 PM
    Moderator
  • I met the same problem.

    Then I used Jeff's code verbatim, it works.

    When using my own code , I got the same error.

    My solution: 1. must define the width and height with the picture.

                        2. must invoke the method mediaCapture.initializeAsync(mediaCaputreSettings) before other methods.



    Friday, June 15, 2012 4:06 AM
  • Thanks Mini,

    Those are great tips!


    Jeff Sanders (MSFT)

    Friday, June 15, 2012 12:52 PM
    Moderator