Files
docs-desktop/dotnet-desktop-guide/framework/wpf/graphics-multimedia/how-to-control-a-mediaelement-play-pause-stop-volume-and-speed.md
T
Andy De George da363692ff Initial WPF content migrated (#17)
* 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
2020-09-04 09:46:28 -07:00

2.5 KiB

title, description, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title description ms.date dev_langs helpviewer_keywords ms.assetid
How to: Control a MediaElement (Play, Pause, Stop, Volume, and Speed) Control playback of media in Windows Presentation foundation (WPF). Start, stop, pause, skip back and forth, and adjust volume and speed. 03/30/2017
csharp
vb
playback of media [WPF], controlling
controlling playback of media [WPF]
multimedia [WPF], controlling playback of media
media [WPF], controlling playback of
6885a730-e054-4c16-8c1e-ffe17b1f7c32

How to: Control a MediaElement (Play, Pause, Stop, Volume, and Speed)

The following example shows how to control playback of media using a xref:System.Windows.Controls.MediaElement. The example creates a simple media player that allows you to play, pause, stop, and skip back and forth in the media as well as adjust the volume and speed ratio.

Example

The code below creates the UI.

Note

The xref:System.Windows.Controls.MediaElement.LoadedBehavior%2A property of xref:System.Windows.Controls.MediaElement must be set to Manual in order to be able to interactively stop, pause, and play the media.

[!code-xamlMediaGallery_snip#MediaElementExampleWholePage]

Example

The code below implements the functionality of the sample UI controls. The xref:System.Windows.Controls.MediaElement.Play%2A, xref:System.Windows.Controls.MediaElement.Pause%2A, and xref:System.Windows.Controls.MediaElement.Stop%2A methods are used to respectively play, pause and stop the media. Changing the xref:System.Windows.Controls.MediaElement.Position%2A property of the xref:System.Windows.Controls.MediaElement allows you to skip around in the media. Finally, the xref:System.Windows.Controls.MediaElement.Volume%2A and xref:System.Windows.Controls.MediaElement.SpeedRatio%2A properties are used to adjust the volume and playback speed of the media.

[!code-csharpMediaGallery_snip#CodeBehindMediaElementExampleWholePage] [!code-vbMediaGallery_snip#CodeBehindMediaElementExampleWholePage]

See also