简体   繁体   中英

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 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

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM