This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Provides access to media playback functionality such as play, pause, fast-forward, rewind, and volume.
public ref class MediaPlayer sealedpublic ref class MediaPlayer sealed : IClosable/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]class MediaPlayer final/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]/// [Windows.Foundation.Metadata.Activatable(196608, "Windows.Foundation.UniversalApiContract")]class MediaPlayer final : IClosable[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)][Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)][Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]public sealed class MediaPlayer[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)][Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)][Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)][Windows.Foundation.Metadata.Activatable(196608, "Windows.Foundation.UniversalApiContract")]public sealed class MediaPlayer : System.IDisposablefunction MediaPlayer()Public NotInheritable Class MediaPlayerPublic NotInheritable Class MediaPlayerImplements IDisposable| Requirements | Description |
|---|---|
| Device family | Windows 10 (introduced in 10.0.10240.0) |
| API contract | Windows.Foundation.UniversalApiContract (introduced in v1.0) |
TheMedia playback section of the documentation contains how-to articles that provide detailed guidance for adding media playback features to your app. The following table lists some of the available articles.
| Topic | Description |
|---|---|
| Play audio and video with MediaPlayer | Shows you how to take advantage of the new features and improvements to the media playback system for UWP apps. |
| Media items, playlists, and tracks | Shows you how to use theMediaSource class, which provides a common way to reference and play back media from different sources such as local or remote files and exposes a common model for accessing media data, regardless of the underlying media format. |
| Integrate with the System Media Transport Controls | Shows you how to integrate your app with the System Media Transport Controls (SMTC). |
| System-supported timed metadata cues | Describes how to take advantage of several formats of timed metadata that may be embedded in media files or streams. |
| Create, schedule, and manage media breaks | Shows you how to create, schedule, and manage media breaks to your media playback app. |
| Play media in the background | Shows you how to configure your app so that media continues to play when your app moves from the foreground to the background. |
| Adaptive Streaming | Describes how to add playback of adaptive streaming multimedia content to a Universal Windows Platform (UWP) apps. |
| Media casting | Shows you how to cast media to remote devices from a Universal Windows app. |
| PlayReady DRM | Describes how to add PlayReady protected media content to your Universal Windows Platform (UWP) app. |
The following SDK samples demonstrate the media playback features available to UWP apps on Windows 10. Use these samples to see the media playback APIs used in context or as a starting point for your own app.
| Windows version | SDK version | Value added |
|---|---|---|
| 1511 | 10586 | AddAudioEffect |
| 1511 | 10586 | RemoveAllEffects |
| 1607 | 14393 | AddVideoEffect |
| 1607 | 14393 | AudioBalance |
| 1607 | 14393 | AudioDevice |
| 1607 | 14393 | BreakManager |
| 1607 | 14393 | CommandManager |
| 1607 | 14393 | GetAsCastingSource |
| 1607 | 14393 | GetSurface |
| 1607 | 14393 | IsMutedChanged |
| 1607 | 14393 | PlaybackSession |
| 1607 | 14393 | RealTimePlayback |
| 1607 | 14393 | SetSurfaceSize |
| 1607 | 14393 | SourceChanged |
| 1607 | 14393 | StepBackwardOneFrame |
| 1607 | 14393 | StepForwardOneFrame |
| 1607 | 14393 | StereoscopicVideoRenderMode |
| 1607 | 14393 | TimelineController |
| 1607 | 14393 | TimelineControllerPositionOffset |
| 1703 | 15063 | CopyFrameToStereoscopicVideoSurfaces |
| 1703 | 15063 | CopyFrameToVideoSurface(IDirect3DSurface) |
| 1703 | 15063 | CopyFrameToVideoSurface(IDirect3DSurface,Rect) |
| 1703 | 15063 | IsVideoFrameServerEnabled |
| 1703 | 15063 | VideoFrameAvailable |
| 1709 | 16299 | RenderSubtitlesToSurface(IDirect3DSurface) |
| 1709 | 16299 | RenderSubtitlesToSurface(IDirect3DSurface,Rect) |
| 1709 | 16299 | SubtitleFrameChanged |
| 1803 | 17134 | AudioStateMonitor |
| Name | Description |
|---|---|
| MediaPlayer() | Initializes a new instance of theMediaPlayer object. |
| Name | Description |
|---|---|
| AudioBalance | Gets or sets a ratio of volume across stereo speakers. |
| AudioCategory | Gets or sets the type of audio that is currently being played. |
| AudioDevice | Gets or sets theDeviceInformation object representing audio device used by theMediaPlayer to render audio. |
| AudioDeviceType | Gets or sets a value that describes the primary usage of the device that is being used to play back audio. |
| AudioStateMonitor | Gets anAudioStateMonitor object that allows a UWP app to determine if any of the app's audio streams are currently being muted or having their volume reduced by the system. |
| AutoPlay | Gets or sets a Boolean value indicating if playback automatically starts after the media is loaded. |
| BreakManager | Gets theMediaBreakManager associated with theMediaPlayer, which provides information about and control over media breaks for the player. |
| BufferingProgress | Gets the amount of buffering that is completed for the media content, expressed as a percentage. Note MediaPlayer.BufferingProgress may be altered or unavailable after Windows 10, version 1607. Instead, use theMediaPlayer.PlaybackSession property to get aMediaPlaybackSession object and then use theMediaPlaybackSession.BufferingProgress property. |
| CanPause | Gets a Boolean value indicating if the media can be paused. Note MediaPlayer.CanPause may be altered or unavailable after Windows 10, version 1607. Instead, use theMediaPlayer.PlaybackSession property to get aMediaPlaybackSession object and then use theMediaPlaybackSession.CanPause property. |
| CanSeek | Gets a Boolean value indicating if the media supports seeking to a specific position. Note MediaPlayer.CanSeek may be altered or unavailable after Windows 10, version 1607. Instead, use theMediaPlayer.PlaybackSession property to get aMediaPlaybackSession object and then use theMediaPlaybackSession.CanSeek property. |
| CommandManager | Gets theMediaPlaybackCommandManager associated with theMediaPlayer, which specifies the behavior of and receives events from the System Media Transport Controls. |
| CurrentState | Gets the current state of media playback. Note MediaPlayer.CurrentState may be altered or unavailable after Windows 10, version 1607. Instead, use theMediaPlayer.PlaybackSession property to get aMediaPlaybackSession object and then use theMediaPlaybackSession.PlaybackState property. |
| IsLoopingEnabled | Gets or sets a Boolean value indicating if the media will playback in a repeating loop. |
| IsMuted | Gets or sets a Boolean value indicating if the audio is muted. |
| IsProtected | Gets a Boolean value indicating if the content is protected by a digital rights management system. Note MediaPlayer.IsProtected may be altered or unavailable after Windows 10, version 1607. Instead, use theMediaPlayer.PlaybackSession property to get aMediaPlaybackSession object and then use theIsProtected property. |
| IsVideoFrameServerEnabled | Gets a value indicating whether video frame server mode is enabled for theMediaPlayer instance. |
| NaturalDuration | Get the actual duration of the media without applying thePlaybackRate. Note MediaPlayer.NaturalDuration may be altered or unavailable after Windows 10, version 1607. Instead, use theMediaPlayer.PlaybackSession property to get aMediaPlaybackSession object and then use theMediaPlaybackSession.NaturalDuration property. |
| PlaybackMediaMarkers | Gets the collection of timeline markers for the media. Note MediaPlayer.PlaybackMediaMarkers may be altered or unavailable after Windows 10, version 1607. Instead, useMediaPlaybackItem.TimedMetadataTracks to manage data or text cues. For more information, seeMedia playback with MediaSource. |
| PlaybackRate | Gets or sets the playback rate, expressed as a ratio. Note MediaPlayer.PlaybackRate may be altered or unavailable after Windows 10, version 1607. Instead, use theMediaPlayer.PlaybackSession property to get aMediaPlaybackSession object and then use theMediaPlaybackSession.PlaybackRate property. |
| PlaybackSession | Gets theMediaPlaybackSession associated with theMediaPlayer, which provides information about the state of the current playback session and provides events for responding to changes in playback session state. |
| Position | Gets or sets the playback position within the media. Note MediaPlayer.Position may be altered or unavailable after Windows 10, version 1607. Instead, use theMediaPlayer.PlaybackSession property to get aMediaPlaybackSession object and then use theMediaPlaybackSession.Position property. |
| ProtectionManager | Gets or sets the content protection manager for the media. |
| RealTimePlayback | Gets or sets a value that configures theMediaPlayer for real-time scenarios such as live streaming video. |
| Source | Sets the playback source of the media player. |
| StereoscopicVideoRenderMode | Gets or sets a value indicating the current stereoscopic render mode. |
| SystemMediaTransportControls | Gets an instance of the SystemMediaTransportControls class to enable user control of playback of theMediaPlayer and to allow the app to show information about the currently playing content in the system UI. |
| TimelineController | Gets or sets theMediaTimelineController associated with theMediaPlayer. Use this property to manipulate multipleMediaPlayer instances with a single timeline control. |
| TimelineControllerPositionOffset | Gets or sets the offset applied to the position of theMediaTimelineController associated with theMediaPlayer. |
| Volume | Get or sets the audio volume for media playback. |
| Name | Description |
|---|---|
| AddAudioEffect(String, Boolean, IPropertySet) | Adds an audio effect to the playback stream of theMediaPlayer. |
| AddVideoEffect(String, Boolean, IPropertySet) | Applies a video effect to media playback. |
| Close() | Closes theMediaPlayer and disposes of associated resources. |
| CopyFrameToStereoscopicVideoSurfaces(IDirect3DSurface, IDirect3DSurface) | Copies the video frame currently displayed by theMediaPlayer to the two providedIDirect3DSurface objects which represent the left eye and right eye content of a stereoscopic video frame. |
| CopyFrameToVideoSurface(IDirect3DSurface, Rect) | Copies the current video frame from theMediaPlayer to the specified target rectangle within the providedIDirect3DSurface. |
| CopyFrameToVideoSurface(IDirect3DSurface) | Copies the current video frame from theMediaPlayer to the providedIDirect3DSurface. |
| Dispose() | Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. |
| GetAsCastingSource() | Gets aCastingSource representing theMediaPlayer, which allows its media to be cast to other devices. |
| GetSurface(Compositor) | Gets aMediaPlayerSurface object for theMediaPlayer, which allows you to render the player's contents using aCompositor without relying on the XAML framework. |
| Pause() | Pauses media playback. |
| Play() | Starts media playback. |
| RemoveAllEffects() | Removes all effects from the playback stream of theMediaPlayer. |
| RenderSubtitlesToSurface(IDirect3DSurface, Rect) | Requests for the system to render the current subtitle text to the specified target rectangle within the providedIDirect3DSurface. |
| RenderSubtitlesToSurface(IDirect3DSurface) | Requests for the system to render the current subtitle text to the providedIDirect3DSurface. |
| SetFileSource(IStorageFile) | Set the media source to a file. Note MediaPlayer.SetFileSource may be altered or unavailable after Windows 10. UseMediaPlayer.Source instead. |
| SetMediaSource(IMediaSource) | Sets the media source for playback. Note MediaPlayer.SetMediaSource may be altered or unavailable after Windows 10. UseMediaPlayer.Source instead. |
| SetStreamSource(IRandomAccessStream) | Sets the media source to a stream. Note MediaPlayer.SetMediaSource may be altered or unavailable after Windows 10. UseMediaPlayer.Source instead. |
| SetSurfaceSize(Size) | Sets the size of the composition surface returned byGetSurface. |
| SetUriSource(Uri) | Sets the path to the media. Note MediaPlayer.SetUriSource may be altered or unavailable after Windows 10. UseMediaPlayer.Source instead. |
| StepBackwardOneFrame() | Causes the playback position of theMediaPlayer to move backward by .042 seconds, which corresponds to one frame at 24 fps, regardless of the actual frame rate of the content being played. |
| StepForwardOneFrame() | Causes theMediaPlayer to move forward in the current media by one frame. |
| Name | Description |
|---|---|
| BufferingEnded | Occurs when buffering has finished. Note MediaPlayer.BufferingEnded may be altered or unavailable after Windows 10, version 1607. Instead, use theMediaPlayer.PlaybackSession property to get aMediaPlaybackSession object and then use theMediaPlaybackSession.BufferingEnded event. |
| BufferingStarted | Occurs when buffering has started. Note MediaPlayer.BufferingStarted may be altered or unavailable after Windows 10, version 1607. Instead, use theMediaPlayer.PlaybackSession property to get aMediaPlaybackSession object and then use theMediaPlaybackSession.BufferingStarted event. |
| CurrentStateChanged | Occurs when the state of the media player has changed. Note MediaPlayer.CurrentStateChanged may be altered or unavailable after Windows 10, version 1607. Instead, use theMediaPlayer.PlaybackSession property to get aMediaPlaybackSession object and then use theMediaPlaybackSession.PlaybackStateChanged event. |
| IsMutedChanged | Occurs when the current muted status of theMediaPlayer changes. |
| MediaEnded | Occurs when the media has finished playback. |
| MediaFailed | Occurs when an error is encountered. |
| MediaOpened | Occurs when the media is opened. |
| MediaPlayerRateChanged | Occurs when the media playback rate has changed. Note MediaPlayer.MediaPlayerRateChanged may be altered or unavailable after Windows 10, version 1607. Instead, use theMediaPlayer.PlaybackSession property to get aMediaPlaybackSession object and then use theMediaPlaybackSession.PlaybackRateChanged event. |
| PlaybackMediaMarkerReached | Occurs when a media marker has been reached during playback. Note MediaPlayer.PlaybackMediaMarkerReached may be altered or unavailable after Windows 10, version 1607. Instead, useMediaPlaybackItem.TimedMetadataTracks to manage data or text cues. For more information, seeMedia playback with MediaSource. |
| SeekCompleted | Occurs when a seek operation has finished. Note MediaPlayer.SeekCompleted may be altered or unavailable after Windows 10, version 1607. Instead, use theMediaPlayer.PlaybackSession property to get aMediaPlaybackSession object and then use theMediaPlaybackSession.SeekCompleted event. |
| SourceChanged | Occurs when the media source for theMediaPlayer changes. |
| SubtitleFrameChanged | Occurs when the current subtitle content has changed while theMediaPlayer is in frame server mode. |
| VideoFrameAvailable | Occurs whenIsVideoFrameServerEnabled is set to true and a new video frame is available for processing. |
| VolumeChanged | Occurs when the volume of the audio has changed. |
Was this page helpful?
Need help with this topic?
Want to try using Ask Learn to clarify or guide you through this topic?
Was this page helpful?
Want to try using Ask Learn to clarify or guide you through this topic?