Captures photos, audio recordings and videos.
Syntax
public sealed class MediaCapture : Object
Attributes
- ActivatableAttribute(NTDDI_WIN8)
- DualApiPartitionAttribute()
- MarshalingBehaviorAttribute(Standard)
- ThreadingAttribute(MTA)
- VersionAttribute(NTDDI_WIN8)
Members
The MediaCapture class has these types of members:
Constructors
The MediaCapture class has these constructors.
| Constructor | Description |
|---|---|
| MediaCapture | Creates a new instance of the MediaCapture object. |
Events
The MediaCapture class has these events.
| Event | Description |
|---|---|
| Failed | Raised when an error occurs during media capture. |
| RecordLimitationExceeded | Occurs when the record limit is exceeded. |
Methods
The MediaCapture class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.
| Method | Description |
|---|---|
| AddEffectAsync | Adds an audio or video effect. |
| CapturePhotoToStorageFileAsync | Captures a photo to a storage file. |
| CapturePhotoToStreamAsync | Captures a photo to a random-access stream. |
| ClearEffectsAsync | Removes all audio and video effects from a stream. |
| GetEncoderProperty | Gets the value of an encoding property. |
| GetPreviewMirroring | Queries whether the video stream is mirrored horizontally. |
| GetPreviewRotation | Gets the rotation of the video preview stream. |
| GetRecordRotation | Gets the rotation of the recorded video. |
| InitializeAsync() | Initializes the MediaCapture object, using default settings. |
| InitializeAsync(MediaCaptureInitializationSettings) | Initializes the MediaCapture object. |
| SetEncoderProperty | Sets an encoding property. |
| SetPreviewMirroring | Enables or disables horizontal mirroring of the video preview stream. |
| SetPreviewRotation | Rotates the video preview stream. |
| SetRecordRotation | Rotates the recorded video. |
| StartPreviewAsync | Starts preview. |
| StartPreviewToCustomSinkAsync(MediaEncodingProfile, IMediaExtension) | Starts sending a preview stream to a custom media sink using the specified encoding profile. |
| StartPreviewToCustomSinkAsync(MediaEncodingProfile, String, IPropertySet) | Starts sending a preview stream to a custom media sink using the specified encoding profile and sink settings. |
| StartRecordToCustomSinkAsync(MediaEncodingProfile, IMediaExtension) | Start recording to a custom media sink using the specified encoding profile. |
| StartRecordToCustomSinkAsync(MediaEncodingProfile, String, IPropertySet) | Start recording to a custom media sink using the specified encoding profile and sink settings. |
| StartRecordToStorageFileAsync | Starts recording asynchronously to a storage file. |
| StartRecordToStreamAsync | Starts recording to a random-access stream. |
| StopPreviewAsync | Stops preview. |
| StopRecordAsync | Stops recording. |
Properties
The MediaCapture class has these properties.
| Property | Access type | Description |
|---|---|---|
| Read-only | Gets an object that controls settings for the microphone. | |
| Read-only | Gets the configuration settings for the MediaCapture object. | |
| Read-only | Gets an object that controls settings for the video camera. |
Remarks
In apps that use C# or C++ in Windows 8, the first use of the MediaCapture object to call InitializeAsync should be on the STA thread. Calls from an MTA thread may result in undefined behavior.
InitializeAsync will launch a consent prompt to get the user's permission for the app to access the microphone or camera. InitializeAsync should be called from the main UI thread of your app. For more information, see Guidelines for enabling sensitive devices.
If an app is previewing and it goes into a non-visible state, previewing should be stopped. If the app reenters a visible state, the MediaCapture needs to be recreated.
MediaCapture only supports one pass CBR encoding.
Notes on JPEG: JPEG types are passthrough only. To capture an image, the image encoding profile can be set to Auto or you need to specify an encoding profile that matches the native type. To add an effect, you need to switch to an uncompressed video native media type, such as NV12 or RGB32.
Notes on H.264: If the native type is H.264, you can record using a video media type with type identical to the native type. You cannot add an effect to an H.264 native type stream. To capture video, the image encoding profile can be set to Auto or you need to specify an encoding profile that matches the native type.
Note : This class is not agile, which means that you need to consider its threading model and marshaling behavior. For more info, see Threading and Marshaling (C++/CX) and Using Windows Runtime objects in a multithreaded environment (.NET).
Examples
The following code sample shows how to create and initialize a MediaCapture object.
// Create and initialze the MediaCapture object. function initMediaCapture() { oMediaCapture = null; oMediaCapture = new Windows.Media.Capture.MediaCapture(); oMediaCapture.initializeAsync(captureInitSettings).then (function (result) { createProfile(); }, errorHandler); }
See the Media Capture Sample for an example of using media capture.
If you’d like to try working with media capture and other key Windows 8 features, download the hands-on labs for Windows 8. These labs provide a modular, step-by-step introduction to creating a sample Windows Store app in the programming language of your choice (JavaScript and HTML or C# and XAML).
Requirements
|
Minimum supported client | Windows 8 [Windows Store apps, desktop apps] |
|---|---|
|
Minimum supported server | Windows Server 2012 [Windows Store apps, desktop apps] |
|
Namespace |
|
|
Metadata |
|
|
Capabilities |
|
See also
- Guidelines for enabling sensitive devices
- Roadmaps
- Adding multimedia to Windows Store apps using C++, C#, or Visual Basic
- Adding multimedia to Windows Store apps using JavaScript
- Samples
- Media capture sample
- Camera capture UI sample
- Camera options UI sample
- Device enumeration sample
- Real-Time communication sample
- Media extension sample
- Hands-on labs for Windows 8
- Other resources
- Supported audio and video formats
Build date: 12/4/2012