MediaPlayer MediaPlayer MediaPlayer MediaPlayer MediaPlayer Class

Definition

Some information relates to pre-released product which may be substantially modified before it’s commercially released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Prerelease APIs are identified by a Prerelease label.

[Contains prerelease APIs.]
Provides access to media playback functionality such as play, pause, fast-forward, rewind, and volume.

public : sealed class MediaPlayer : IClosable, IMediaPlayer, IMediaPlayer2, IMediaPlayer3, IMediaPlayer4, IMediaPlayer5, IMediaPlayer6, IMediaPlayerEffects, IMediaPlayerEffects2, IMediaPlayerSource, IMediaPlayerSource2
struct winrt::Windows::Media::Playback::MediaPlayer : IClosable, IMediaPlayer, IMediaPlayer2, IMediaPlayer3, IMediaPlayer4, IMediaPlayer5, IMediaPlayer6, IMediaPlayerEffects, IMediaPlayerEffects2, IMediaPlayerSource, IMediaPlayerSource2
public sealed class MediaPlayer : IDisposable, IMediaPlayer, IMediaPlayer2, IMediaPlayer3, IMediaPlayer4, IMediaPlayer5, IMediaPlayer6, IMediaPlayerEffects, IMediaPlayerEffects2, IMediaPlayerSource, IMediaPlayerSource2
Public NotInheritable Class MediaPlayer Implements IDisposable, IMediaPlayer, IMediaPlayer2, IMediaPlayer3, IMediaPlayer4, IMediaPlayer5, IMediaPlayer6, IMediaPlayerEffects, IMediaPlayerEffects2, IMediaPlayerSource, IMediaPlayerSource2
var mediaPlayer = new mediaPlayer();
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

The Media 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 the MediaSource 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.

Media playback SDK samples

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.

Constructors

MediaPlayer() MediaPlayer() MediaPlayer() MediaPlayer() MediaPlayer()

Initializes a new instance of the MediaPlayer object.

Properties

AudioBalance AudioBalance AudioBalance AudioBalance AudioBalance

Gets or sets a ratio of volume across stereo speakers.

AudioCategory AudioCategory AudioCategory AudioCategory AudioCategory

Gets or sets the type of audio that is currently being played.

AudioDevice AudioDevice AudioDevice AudioDevice AudioDevice

Gets or sets the DeviceInformation object representing audio device used by the MediaPlayer to render audio.

AudioDeviceType AudioDeviceType AudioDeviceType AudioDeviceType AudioDeviceType

Gets or sets a value that describes the primary usage of the device that is being used to play back audio.

AudioStateMonitor AudioStateMonitor AudioStateMonitor AudioStateMonitor AudioStateMonitor

Prerelease. Gets an AudioStateMonitor 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 AutoPlay AutoPlay AutoPlay AutoPlay

Gets or sets a Boolean value indicating if playback automatically starts after the media is loaded.

BreakManager BreakManager BreakManager BreakManager BreakManager

Gets the MediaBreakManager associated with the MediaPlayer, which provides information about and control over media breaks for the player.

BufferingProgress BufferingProgress BufferingProgress BufferingProgress 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 the MediaPlayer.PlaybackSession property to get a MediaPlaybackSession object and then use the MediaPlaybackSession.BufferingProgress property.

CanPause CanPause CanPause CanPause 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 the MediaPlayer.PlaybackSession property to get a MediaPlaybackSession object and then use the MediaPlaybackSession.CanPause property.

CanSeek CanSeek CanSeek CanSeek 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 the MediaPlayer.PlaybackSession property to get a MediaPlaybackSession object and then use the MediaPlaybackSession.CanSeek property.

CommandManager CommandManager CommandManager CommandManager CommandManager

Gets the MediaPlaybackCommandManager associated with the MediaPlayer, which specifies the behavior of and receives events from the System Media Transport Controls.

CurrentState CurrentState CurrentState CurrentState CurrentState

Gets the current state of media playback.

Note

MediaPlayer.CurrentState may be altered or unavailable after Windows 10, version 1607. Instead, use the MediaPlayer.PlaybackSession property to get a MediaPlaybackSession object and then use the MediaPlaybackSession.PlaybackState property.

IsLoopingEnabled IsLoopingEnabled IsLoopingEnabled IsLoopingEnabled IsLoopingEnabled

Gets or sets a Boolean value indicating if the media will playback in a repeating loop.

IsMuted IsMuted IsMuted IsMuted IsMuted

Gets or sets a Boolean value indicating if the audio is muted.

IsProtected IsProtected IsProtected IsProtected 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 the MediaPlayer.PlaybackSession property to get a MediaPlaybackSession object and then use the IsProtected property.

IsVideoFrameServerEnabled IsVideoFrameServerEnabled IsVideoFrameServerEnabled IsVideoFrameServerEnabled IsVideoFrameServerEnabled

Gets a value indicating whether video frame server mode is enabled for the MediaPlayer instance.

NaturalDuration NaturalDuration NaturalDuration NaturalDuration NaturalDuration

Get the actual duration of the media without applying the PlaybackRate.

Note

MediaPlayer.NaturalDuration may be altered or unavailable after Windows 10, version 1607. Instead, use the MediaPlayer.PlaybackSession property to get a MediaPlaybackSession object and then use the MediaPlaybackSession.NaturalDuration property.

PlaybackMediaMarkers PlaybackMediaMarkers PlaybackMediaMarkers PlaybackMediaMarkers PlaybackMediaMarkers

Gets the collection of timeline markers for the media.

Note

MediaPlayer.PlaybackMediaMarkers may be altered or unavailable after Windows 10, version 1607. Instead, use MediaPlaybackItem.TimedMetadataTracks to manage data or text cues. For more information, see Media playback with MediaSource.

PlaybackRate PlaybackRate PlaybackRate PlaybackRate PlaybackRate

Gets or sets the playback rate, expressed as a percentage.

Note

MediaPlayer.PlaybackRate may be altered or unavailable after Windows 10, version 1607. Instead, use the MediaPlayer.PlaybackSession property to get a MediaPlaybackSession object and then use the MediaPlaybackSession.PlaybackRate property.

PlaybackSession PlaybackSession PlaybackSession PlaybackSession PlaybackSession

Gets the MediaPlaybackSession associated with the MediaPlayer, which provides information about the state of the current playback session and provides events for responding to changes in playback session state.

Position Position Position Position 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 the MediaPlayer.PlaybackSession property to get a MediaPlaybackSession object and then use the MediaPlaybackSession.Position property.

ProtectionManager ProtectionManager ProtectionManager ProtectionManager ProtectionManager

Gets or sets the content protection manager for the media.

RealTimePlayback RealTimePlayback RealTimePlayback RealTimePlayback RealTimePlayback

Gets or sets a value that configures the MediaPlayer for real-time scenarios.

Source Source Source Source Source

Sets the playback source of the media player.

StereoscopicVideoRenderMode StereoscopicVideoRenderMode StereoscopicVideoRenderMode StereoscopicVideoRenderMode StereoscopicVideoRenderMode

Gets or sets a value indicating the current stereoscopic render mode.

SystemMediaTransportControls SystemMediaTransportControls SystemMediaTransportControls SystemMediaTransportControls SystemMediaTransportControls

Gets an instance of the SystemMediaTransportControls class to enable user control of playback of the MediaPlayer and to allow the app to show information about the currently playing content in the system UI.

TimelineController TimelineController TimelineController TimelineController TimelineController

Gets or sets the MediaTimelineController associated with the MediaPlayer. Use this property to manipulate multiple MediaPlayer instances with a single timeline control.

TimelineControllerPositionOffset TimelineControllerPositionOffset TimelineControllerPositionOffset TimelineControllerPositionOffset TimelineControllerPositionOffset

Gets or sets the offset applied to the position of the MediaTimelineController associated with the MediaPlayer.

Volume Volume Volume Volume Volume

Get or sets the audio volume for media playback.

Methods

AddAudioEffect(String, Boolean, IPropertySet) AddAudioEffect(String, Boolean, IPropertySet) AddAudioEffect(String, Boolean, IPropertySet) AddAudioEffect(String, Boolean, IPropertySet) AddAudioEffect(String, Boolean, IPropertySet)

Adds an audio effect to the playback stream of the MediaPlayer.

AddVideoEffect(String, Boolean, IPropertySet) AddVideoEffect(String, Boolean, IPropertySet) AddVideoEffect(String, Boolean, IPropertySet) AddVideoEffect(String, Boolean, IPropertySet) AddVideoEffect(String, Boolean, IPropertySet)

Applies a video effect to media playback.

Close() Close() Close() Close() Close()

Closes the MediaPlayer and disposes of associated resources.

CopyFrameToStereoscopicVideoSurfaces(IDirect3DSurface, IDirect3DSurface) CopyFrameToStereoscopicVideoSurfaces(IDirect3DSurface, IDirect3DSurface) CopyFrameToStereoscopicVideoSurfaces(IDirect3DSurface, IDirect3DSurface) CopyFrameToStereoscopicVideoSurfaces(IDirect3DSurface, IDirect3DSurface) CopyFrameToStereoscopicVideoSurfaces(IDirect3DSurface, IDirect3DSurface)

Copies the video frame currently displayed by the MediaPlayer to the two provided IDirect3DSurface objects which represent the left eye and right eye content of a stereoscopic video frame.

CopyFrameToVideoSurface(IDirect3DSurface) CopyFrameToVideoSurface(IDirect3DSurface) CopyFrameToVideoSurface(IDirect3DSurface) CopyFrameToVideoSurface(IDirect3DSurface) CopyFrameToVideoSurface(IDirect3DSurface)

Copies the current video frame from the MediaPlayer to the provided IDirect3DSurface.

CopyFrameToVideoSurface(IDirect3DSurface, Rect) CopyFrameToVideoSurface(IDirect3DSurface, Rect) CopyFrameToVideoSurface(IDirect3DSurface, Rect) CopyFrameToVideoSurface(IDirect3DSurface, Rect) CopyFrameToVideoSurface(IDirect3DSurface, Rect)

Copies the current video frame from the MediaPlayer to the specified target rectangle within the provided IDirect3DSurface.

Dispose() Dispose() Dispose() Dispose() Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

GetAsCastingSource() GetAsCastingSource() GetAsCastingSource() GetAsCastingSource() GetAsCastingSource()

Gets a CastingSource representing the MediaPlayer, which allows it's media to be cast to other devices.

GetSurface(Compositor) GetSurface(Compositor) GetSurface(Compositor) GetSurface(Compositor) GetSurface(Compositor)

Gets a MediaPlayerSurface object for the MediaPlayer, which allows you to render the player's contents using a Compositor without relying on the XAML framework.

Pause() Pause() Pause() Pause() Pause()

Pauses media playback.

Play() Play() Play() Play() Play()

Starts media playback.

RemoveAllEffects() RemoveAllEffects() RemoveAllEffects() RemoveAllEffects() RemoveAllEffects()

Removes all effects from the playback stream of the MediaPlayer.

RenderSubtitlesToSurface(IDirect3DSurface) RenderSubtitlesToSurface(IDirect3DSurface) RenderSubtitlesToSurface(IDirect3DSurface) RenderSubtitlesToSurface(IDirect3DSurface) RenderSubtitlesToSurface(IDirect3DSurface)

Requests for the system to render the current subtitle text to the provided IDirect3DSurface.

RenderSubtitlesToSurface(IDirect3DSurface, Rect) RenderSubtitlesToSurface(IDirect3DSurface, Rect) RenderSubtitlesToSurface(IDirect3DSurface, Rect) RenderSubtitlesToSurface(IDirect3DSurface, Rect) RenderSubtitlesToSurface(IDirect3DSurface, Rect)

Requests for the system to render the current subtitle text to the specified target rectangle within the provided IDirect3DSurface.

SetFileSource(IStorageFile) SetFileSource(IStorageFile) SetFileSource(IStorageFile) SetFileSource(IStorageFile) SetFileSource(IStorageFile)

Set the media source to a file.

Note

MediaPlayer.SetFileSource may be altered or unavailable after Windows 10. Use MediaPlayer.Source instead.

SetMediaSource(IMediaSource) SetMediaSource(IMediaSource) SetMediaSource(IMediaSource) SetMediaSource(IMediaSource) SetMediaSource(IMediaSource)

Sets the media source for playback.

Note

MediaPlayer.SetMediaSource may be altered or unavailable after Windows 10. Use MediaPlayer.Source instead.

SetStreamSource(IRandomAccessStream) SetStreamSource(IRandomAccessStream) SetStreamSource(IRandomAccessStream) SetStreamSource(IRandomAccessStream) SetStreamSource(IRandomAccessStream)

Sets the media source to a stream.

Note

MediaPlayer.SetMediaSource may be altered or unavailable after Windows 10. Use MediaPlayer.Source instead.

SetSurfaceSize(Size) SetSurfaceSize(Size) SetSurfaceSize(Size) SetSurfaceSize(Size) SetSurfaceSize(Size)

Sets the size of the composition surface returned by GetSurface.

SetUriSource(Uri) SetUriSource(Uri) SetUriSource(Uri) SetUriSource(Uri) SetUriSource(Uri)

Sets the path to the media.

Note

MediaPlayer.SetUriSource may be altered or unavailable after Windows 10. Use MediaPlayer.Source instead.

StepBackwardOneFrame() StepBackwardOneFrame() StepBackwardOneFrame() StepBackwardOneFrame() StepBackwardOneFrame()

Causes the playback position of the MediaPlayer 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() StepForwardOneFrame() StepForwardOneFrame() StepForwardOneFrame() StepForwardOneFrame()

Causes the MediaPlayer to move forward in the current media by one frame.

Events

BufferingEnded BufferingEnded BufferingEnded BufferingEnded BufferingEnded

Occurs when buffering has finished.

Note

MediaPlayer.BufferingEnded may be altered or unavailable after Windows 10, version 1607. Instead, use the MediaPlayer.PlaybackSession property to get a MediaPlaybackSession object and then use the MediaPlaybackSession.BufferingEnded event.

BufferingStarted BufferingStarted BufferingStarted BufferingStarted BufferingStarted

Occurs when buffering has started.

Note

MediaPlayer.BufferingStarted may be altered or unavailable after Windows 10, version 1607. Instead, use the MediaPlayer.PlaybackSession property to get a MediaPlaybackSession object and then use the MediaPlaybackSession.BufferingStarted event.

CurrentStateChanged CurrentStateChanged CurrentStateChanged CurrentStateChanged 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 the MediaPlayer.PlaybackSession property to get a MediaPlaybackSession object and then use the MediaPlaybackSession.PlaybackStateChanged event.

IsMutedChanged IsMutedChanged IsMutedChanged IsMutedChanged IsMutedChanged

Occurs when the current muted status of the MediaPlayer changes.

MediaEnded MediaEnded MediaEnded MediaEnded MediaEnded

Occurs when the media has finished playback.

MediaFailed MediaFailed MediaFailed MediaFailed MediaFailed

Occurs when an error is encountered.

MediaOpened MediaOpened MediaOpened MediaOpened MediaOpened

Occurs when the media is opened.

MediaPlayerRateChanged MediaPlayerRateChanged MediaPlayerRateChanged MediaPlayerRateChanged MediaPlayerRateChanged

Occurs when the media playback rate has changed.

Note

MediaPlayer.MediaPlayerRateChanged may be altered or unavailable after Windows 10, version 1607. Instead, use the MediaPlayer.PlaybackSession property to get a MediaPlaybackSession object and then use the MediaPlaybackSession.PlaybackRateChanged event.

PlaybackMediaMarkerReached PlaybackMediaMarkerReached PlaybackMediaMarkerReached PlaybackMediaMarkerReached 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, use MediaPlaybackItem.TimedMetadataTracks to manage data or text cues. For more information, see Media playback with MediaSource.

SeekCompleted SeekCompleted SeekCompleted SeekCompleted SeekCompleted

Occurs when a seek operation has finished.

Note

MediaPlayer.SeekCompleted may be altered or unavailable after Windows 10, version 1607. Instead, use the MediaPlayer.PlaybackSession property to get a MediaPlaybackSession object and then use the MediaPlaybackSession.SeekCompleted event.

SourceChanged SourceChanged SourceChanged SourceChanged SourceChanged

Occurs when the media source for the MediaPlayer changes.

SubtitleFrameChanged SubtitleFrameChanged SubtitleFrameChanged SubtitleFrameChanged SubtitleFrameChanged

Occurs when the current subtitle content has changed while the MediaPlayer is in frame server mode.

VideoFrameAvailable VideoFrameAvailable VideoFrameAvailable VideoFrameAvailable VideoFrameAvailable

Occurs when IsVideoFrameServerEnabled is set to true and a new video frame is available for processing.

VolumeChanged VolumeChanged VolumeChanged VolumeChanged VolumeChanged

Occurs when the volume of the audio has changed.