CameraCaptureUI.CaptureFileAsync | captureFileAsync method

Applies to Windows only

Launches the CameraCaptureUI user interface.

Syntax


Public Function CaptureFileAsync(
  mode As CameraCaptureUIMode 
) As IAsyncOperation(Of StorageFile)

Parameters

mode

Type: CameraCaptureUIMode

Specifies whether the user interface that will be shown allows the user to capture a photo, capture a video, or capture both photos and videos.

Return value

Type: IAsyncOperation<StorageFile>

When this operation completes, a StorageFile object is returned.

Remarks

Call CaptureFileAsync to launch the UI. The user has control over when to start the capture. When the asynchronous operation completes, a StorageFile object is returned.

Examples

The following example calls CaptureFileAsync, and displays a message that indicates if the capture was successful.


// Take a photo using the default JPEG format.
function takepicture() {
    var captureUI = new Windows.Media.Capture.CameraCaptureUI();
    captureUI.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.photo).then(function (capturedItem) {
        if (capturedItem) {
            document.getElementById("message").innerHTML = "User captured a photo."
        }
        else {
            document.getElementById("message").innerHTML = "User didn't capture a photo."
        }
    });
}


The following example shows how to set the properties of VideoSettings, and then how to call CaptureFileAsync to capture a video.


// Captures a video using the specified settings.
function captureVideo() {
    var captureUI = new Windows.Media.Capture.CameraCaptureUI();
    captureUI.videoSettings.allowTrimming = true;
    captureUI.videoSettings.format = Windows.Media.Capture.CameraCaptureUIVideoFormat.wmv;
    captureUI.videoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxVideoResolution.standardDefinition;
    captureUI.videoSettings.maxDurationInSeconds = 3;
    captureUI.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.video).then(function (file) {
        if (file) {
            document.getElementById("message").innerHTML = "User captured a video."
        }
        else {
            document.getElementById("message").innerHTML = "User didn't capture a video."
        }
    });
}


Here is some code that launches the CameraCaptureUI. And if there is a captured file, it previews it in a MediaElement.


<MediaElement x:Name="mediaPreivew"
              Width="320" />



async private void CameraCaptureUI_Click(object sender, RoutedEventArgs e)
{
    CameraCaptureUI cameraUI = new CameraCaptureUI();
    
    Windows.Storage.StorageFile capturedMedia = 
        await cameraUI.CaptureFileAsync(CameraCaptureUIMode.Video);

    if (capturedMedia != null)
    {
        var stream = await capturedMedia.OpenAsync(FileAccessMode.Read);

        mediaPreivew.SetSource(stream, capturedMedia.ContentType);
        mediaPreivew.Play();
    }
}


Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

None supported

Namespace

Windows.Media.Capture
Windows::Media::Capture [C++]

Metadata

Windows.winmd

Capabilities

webcam
microphone

See also

CameraCaptureUI

 

 

Show:
© 2014 Microsoft