MediaElement::Volume Property
Gets or sets the media's volume.
Assembly: PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
<object Volume="double" .../>
Property Value
Type: System::DoubleThe media's volume represented on a linear scale between 0 and 1. The default is 0.5.
The following example shows how to control playback of media using a 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.
The code below creates the UI.
Note |
|---|
The LoadedBehavior property of MediaElement must be set to Manual in order to be able to interactively stop, pause, and play the media. |
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="SDKSample.MediaElementExample" > <StackPanel Background="Black"> <!-- To interactively stop, pause, and play the media, the LoadedBehavior property of the MediaElement must be set to "Manual". --> <MediaElement Source="media\numbers.wmv" Name="myMediaElement" Width="450" Height="250" LoadedBehavior="Manual" UnloadedBehavior="Stop" Stretch="Fill" MediaOpened="Element_MediaOpened" MediaEnded="Element_MediaEnded"/> <StackPanel HorizontalAlignment="Center" Width="450" Orientation="Horizontal"> <!-- Play button. --> <Image Source="images\UI_play.gif" MouseDown="OnMouseDownPlayMedia" Margin="5" /> <!-- Pause button. --> <Image Source="images\UI_pause.gif" MouseDown="OnMouseDownPauseMedia" Margin="5" /> <!-- Stop button. --> <Image Source="images\UI_stop.gif" MouseDown="OnMouseDownStopMedia" Margin="5" /> <!-- Volume slider. This slider allows a Volume range between 0 and 1. --> <TextBlock Foreground="White" VerticalAlignment="Center" Margin="5" >Volume</TextBlock> <Slider Name="volumeSlider" VerticalAlignment="Center" ValueChanged="ChangeMediaVolume" Minimum="0" Maximum="1" Value="0.5" Width="70"/> <!-- Volume slider. This slider allows you to change the speed of the media playback. --> <TextBlock Foreground="White" Margin="5" VerticalAlignment="Center">Speed</TextBlock> <Slider Name="speedRatioSlider" VerticalAlignment="Center" ValueChanged="ChangeMediaSpeedRatio" Value="1" Width="70" /> <!-- Seek to slider. Ths slider allows you to jump to different parts of the media playback. --> <TextBlock Foreground="White" Margin="5" VerticalAlignment="Center">Seek To</TextBlock> <Slider Name="timelineSlider" Margin="5" ValueChanged="SeekToMediaPosition" Width="70"/> </StackPanel> </StackPanel> </Page>
The code below implements the functionality of the sample UI controls. The Play, Pause, and Stop methods are used to respectively play, pause and stop the media. Changing the Position property of the MediaElement allows you to skip around in the media. Finally, the Volume and SpeedRatio properties are used to adjust the volume and playback speed of the media.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note