0

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 control must link into the mobile or any other devices.

Few investigations: Tap sound from an adjustment of Ringtone Volume in our mobile. so we need to get the response from Ringtone settings.

I've searched most about this, but couldn't find the solution.

Update

at Slider change event:

Slider slider = sender as Slider; 
double volumeLevel = slider.Value / 10; 
ElementSoundPlayer.Volume = volumeLevel; 
//CurrVolumeLevel = (double)ElementSoundPlayer.Volume; 
CurrVolumeLevel = volumeLevel; 

At pageload:

//player = new MediaPlayer(); 
CurrVolumeLevel = (double)ElementSoundMode.Default; 
ElementSoundPlayer.State = ElementSoundPlayerState.Aut

o

Nico Zhu - MSFT
  • 30,901
  • 2
  • 13
  • 34
Mohana s
  • 37
  • 9
  • I've silly doubt. in our usual smartphone, we have touch sounds and i can hear 1 sound for all the apps it seems. so tap sound is control by system or app owners. Like tap sound is defined or vary from app? – Mohana s Oct 04 '18 at 13:20
  • at Slider change event: Slider slider = sender as Slider; double volumeLevel = slider.Value / 10; ElementSoundPlayer.Volume = volumeLevel; //CurrVolumeLevel = (double)ElementSoundPlayer.Volume; CurrVolumeLevel = volumeLevel; At pageload: this.InitializeComponent(); //player = new MediaPlayer(); CurrVolumeLevel = (double)ElementSoundMode.Default; ElementSoundPlayer.State = ElementSoundPlayerState.Auto; – Mohana s Oct 08 '18 at 06:17

1 Answers1

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.

public MainPage()
{
    this.InitializeComponent();
    ElementSoundPlayer.State = ElementSoundPlayerState.On;
    CurrentVol.Value = ElementSoundPlayer.Volume * 10;
}

private void Slider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
    Slider slider = sender as Slider;
    double volumeLevel = slider.Value / 10;
    ElementSoundPlayer.Volume = volumeLevel;
}

Xaml

<StackPanel>
    <Slider Name="CurrentVol" Maximum="10" ValueChanged="Slider_ValueChanged"/>
    <Button Content="ClickMe"/>
</StackPanel>
Nico Zhu - MSFT
  • 30,901
  • 2
  • 13
  • 34