Windows desktop applications
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

CameraCaptureUI.CaptureFileAsync | captureFileAsync method

Launches the CameraCaptureUI user interface.

Syntax


cameraCaptureUI.captureFileAsync(mode).done( /* Your success and error handlers */ );

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 (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0 [for Xbox, see UWP features that aren't yet supported on Xbox]

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

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

Metadata

Windows.Foundation.UniversalApiContract.winmd

Capabilities

webcam
microphone

Requirements (Windows 8.x and Windows Phone 8.x)

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:
© 2016 Microsoft