Uwp Touch Volume Control
I need to implement Tap (Touch) volume control using UWP code. For example, if I tap a button in my terminal, the volume of tapping sound could control in App settings. This contr
Solution 1:
If you want to implement Tap (Touch) volume and control it's volume, you could refer Sound official documentation.
UWP provides an easily accessible sound system that allows you to simply "flip a switch" and get an immersive audio experience across your entire app.
The ElementSoundPlayer is an integrated sound system within XAML, and when turned on all default controls will play sounds automatically.
ElementSoundPlayer.State = ElementSoundPlayerState.On;
All sounds within the app can be dimmed with the Volume control. However, sounds within the app cannot get louder than the system volume.
To set the app volume level, call:
ElementSoundPlayer.Volume = 0.5;
Where maximum volume (relative to system volume) is 1.0, and minimum is 0.0 (essentially silent).
Update
Please try the following simple code.
publicMainPage()
{
this.InitializeComponent();
ElementSoundPlayer.State = ElementSoundPlayerState.On;
CurrentVol.Value = ElementSoundPlayer.Volume * 10;
}
privatevoidSlider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
Slider slider = sender as Slider;
double volumeLevel = slider.Value / 10;
ElementSoundPlayer.Volume = volumeLevel;
}
Xaml
<StackPanel><SliderName="CurrentVol"Maximum="10"ValueChanged="Slider_ValueChanged"/><ButtonContent="ClickMe"/></StackPanel>
Post a Comment for "Uwp Touch Volume Control"