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
  • 32,367
  • 2
  • 15
  • 36
Mohana s
  • 47
  • 1
  • 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
  • 32,367
  • 2
  • 15
  • 36
  • May i confirm this Sound control for managing the Ringtone volume in windows mobile?. coz nrml media volume control can't control the touch(tap) volume. Touch volume is adjust by ringtone volume. – Mohana s Oct 01 '18 at 06:26
  • Yep, its relative to system volume not media volume. – Nico Zhu Oct 01 '18 at 06:32
  • But it could be managed separately with `ElementSoundPlayer.Volume` property. – Nico Zhu Oct 01 '18 at 06:38
  • Zhu, tried above solution, but failed. it doesn't make changes in app or in system volume. and even i assigned the volume and play with elementplayer also has no changes. so this not helpful. – Mohana s Oct 04 '18 at 13:23
  • Very strange, I could use `ElementSoundPlayer.Volume` to mange elementplayer and it works in my side. Could you share your full code sample? – Nico Zhu Oct 08 '18 at 02:04
  • @Mohanas, you'd better put the code in your case update. – Nico Zhu Oct 08 '18 at 06:22
  • Nico, did ur code supports to change the volume in touch terminal? – Mohana s Oct 08 '18 at 06:25
  • 1
    And the different is the `ElementSoundPlayer.State = ElementSoundPlayerState.On` in my side. – Nico Zhu Oct 08 '18 at 06:42
  • yes after set it 'on', its wrked. but button not having its own touch sound? or we need to play the touch sound individually? – Mohana s Oct 08 '18 at 09:09
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/181463/discussion-between-nico-zhu-msft-and-mohana-s). – Nico Zhu Oct 08 '18 at 09:24
  • UWP button has `ElementSound` and you could also set it in xaml ``. – Nico Zhu Oct 08 '18 at 09:32
  • Thanks a lot, its wrked for me – Mohana s Oct 09 '18 at 10:44