UWP Touch Volume Control

大兔子大兔子 提交于 2019-12-11 15:41:16

问题


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


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


来源:https://stackoverflow.com/questions/52554504/uwp-touch-volume-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!