Plays a media file. If the media is a video file, the draws it to the specified rectangle.
Assembly: PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
Although you can declare an instance of this class in XAML, you cannot load and play its media without using code, because of the dependency on the MediaPlayer class and in particular the Open and Play methods. To play media in XAML only, use a MediaElement.
Despite its name, a can be used to play audio.
Performance Note: A provides fewer features then an MediaElement: does not support layout, input, or focus. However, because it does not support these features, provides performance benefits making them ideal for describing backgrounds, clip art, and for low-level drawing with Visual objects. See Drawing Objects Overview for more information.
To play an audio or video file, you use a and a MediaPlayer. There are two ways to load and play media. The first is to use a MediaPlayer and a by themselves, and the second way is to create your own MediaTimeline to use with the MediaPlayer and .
When distributing media with your application, y ou 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.
The following example uses a and a MediaPlayer to play a video file once.
// // Create a VideoDrawing. // MediaPlayer player = new MediaPlayer(); player.Open(new Uri(@"sampleMedia\xbox.wmv", UriKind.Relative)); VideoDrawing aVideoDrawing = new VideoDrawing(); aVideoDrawing.Rect = new Rect(0, 0, 100, 100); aVideoDrawing.Player = player; // Play the video once. player.Play();
// // Create a VideoDrawing that repeats. // // Create a MediaTimeline. MediaTimeline mTimeline = new MediaTimeline(new Uri(@"sampleMedia\xbox.wmv", UriKind.Relative)); // Set the timeline to repeat. mTimeline.RepeatBehavior = RepeatBehavior.Forever; // Create a clock from the MediaTimeline. MediaClock mClock = mTimeline.CreateClock(); MediaPlayer repeatingVideoDrawingPlayer = new MediaPlayer(); repeatingVideoDrawingPlayer.Clock = mClock; VideoDrawing repeatingVideoDrawing = new VideoDrawing(); repeatingVideoDrawing.Rect = new Rect(150, 0, 100, 100); repeatingVideoDrawing.Player = repeatingVideoDrawingPlayer;
Note that, when you use a MediaTimeline, you use the interactive ClockController returned from the Controller property of the MediaClock to control media playback instead of the interactive methods of MediaPlayer.
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.