* Reset branch for WPF changes * Convert BMP to PNG; fix link-out-of-scope err * Add snippets for WPF... 6794 files!!!! * Add missing snippets * update file updated between migration * Fix paths to include * update breadcrumb and toc * fix index links * fix index links * fix index links * fix markdown
2.6 KiB
title, ms.date, helpviewer_keywords, ms.assetid
| title | ms.date | helpviewer_keywords | ms.assetid | ||
|---|---|---|---|---|---|
| How to: Play Media using a VideoDrawing | 03/30/2017 |
|
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
Contentand setCopyToOutputDirectorytoPreserveNewestorAlways.
Example
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.
Example
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.