mirror of
https://github.com/Stone-Red-Code/docs-desktop.git
synced 2026-09-08 16:06:07 +02:00
* Updated H2 and column headers. * Metadata update. * Minor edits. * Apply suggestions from code review Co-authored-by: Andy (Steve) De George <[email protected]>
35 lines
2.7 KiB
Markdown
35 lines
2.7 KiB
Markdown
---
|
|
title: "How to: Play Media using a VideoDrawing"
|
|
description: Learn how to play Media using a VideoDrawing.
|
|
ms.date: "03/30/2017"
|
|
ms.custom: devdivchpfy22
|
|
helpviewer_keywords:
|
|
- "playback of media [WPF]"
|
|
- "classes [WPF], MediaPlayer"
|
|
ms.assetid: 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-csharp[DrawingMiscSnippets_snip#VideoDrawingExampleInline](~/samples/snippets/csharp/VS_Snippets_Wpf/DrawingMiscSnippets_snip/CSharp/VideoDrawingExample.cs#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-csharp[DrawingMiscSnippets_snip#RepeatingVideoDrawingExampleInline](~/samples/snippets/csharp/VS_Snippets_Wpf/DrawingMiscSnippets_snip/CSharp/VideoDrawingExample.cs#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
|
|
|
|
- <xref:System.Windows.Media.VideoDrawing>
|
|
- [Drawing Objects Overview](drawing-objects-overview.md)
|