The MediaElement
The MediaElement is a WPF element that wraps all the functionality of the MediaPlayer class. Like all elements, the MediaElement is placed directly in your user interface. If you're using the MediaElement to play audio, this fact isn't important, but if you're using the MediaElement for video, you place it where the video window should appear.
A simple MediaElement tag is all you need to play a sound. For example, if you add this markup to your user interface:
<MediaElement Source="test.mp3"></MediaElement>
the test.mp3 audio will be played as soon as it's loaded (which is more or less as soon as the window is loaded).
Playing Audio Programmatically
Usually, you'll want the ability to control playback more precisely. For example, ...
Get Pro WPF in C# 2008: Windows Presentation Foundation with .NET 3.5, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.