Files
Pooja PoojariandAndy De George 692293bda8 US 1889327: Updated H2 and column headers. (#1326)
* Updated H2 and column headers.

* Metadata update.

* Minor edits.

* Apply suggestions from code review

Co-authored-by: Andy (Steve) De George <[email protected]>
2022-03-07 21:22:00 +00:00

2.7 KiB

title, description, ms.date, ms.custom, helpviewer_keywords, ms.assetid
title description ms.date ms.custom helpviewer_keywords ms.assetid
How to: Play Media using a VideoDrawing Learn how to play Media using a VideoDrawing. 03/30/2017 devdivchpfy22
playback of media [WPF]
classes [WPF], MediaPlayer
165d47ed-22ce-4ded-aa6a-aa9b7467de87

How to: Play Media using a VideoDrawing

To play an audio or video file, you use a xref:System.Windows.Media.VideoDrawing and a xref:System.Windows.Media.MediaPlayer. There are two ways to load and play media. The first is to use a xref:System.Windows.Media.MediaPlayer and a xref:System.Windows.Media.VideoDrawing by themselves, and the second way is to create your own xref:System.Windows.Media.MediaTimeline to use with the xref:System.Windows.Media.MediaPlayer and xref:System.Windows.Media.VideoDrawing.

Note

When distributing media with your application, you cannot use a media file as a project resource, like you would an image. In your project file, you must instead set the media type to Content and set CopyToOutputDirectory to PreserveNewest or Always.

Use a VideoDrawing and a MediaPlayer

The following example uses a xref:System.Windows.Media.VideoDrawing and a xref:System.Windows.Media.MediaPlayer to play a video file once.

[!code-csharpDrawingMiscSnippets_snip#VideoDrawingExampleInline]

To gain additional timing control over the media, use a xref:System.Windows.Media.MediaTimeline with the xref:System.Windows.Media.MediaPlayer and xref:System.Windows.Media.VideoDrawing objects. The xref:System.Windows.Media.MediaTimeline enables you to specify whether the video should repeat.

Use a MediaTimeline

The following example uses a xref:System.Windows.Media.MediaTimeline with the xref:System.Windows.Media.MediaPlayer and xref:System.Windows.Media.VideoDrawing objects to play a video repeatedly.

[!code-csharpDrawingMiscSnippets_snip#RepeatingVideoDrawingExampleInline]

Note that, when you use a xref:System.Windows.Media.MediaTimeline, you use the interactive xref:System.Windows.Media.Animation.ClockController returned from the xref:System.Windows.Media.Animation.Clock.Controller%2A property of the xref:System.Windows.Media.MediaClock to control media playback instead of the interactive methods of xref:System.Windows.Media.MediaPlayer.

See also