UWP 触控音量控制 [英] UWP Touch Volume Control

查看:29
本文介绍了UWP 触控音量控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 UWP 代码实现 Tap (Touch) 音量控制.

例如,如果我点击终端中的一个按钮,点击声音的音量可以在应用设置中进行控制.此控件必须链接到移动设备或任何其他设备.

很少有调查:在我们的手机中通过调整铃声音量来点击声音.所以我们需要从铃声设置中获得响应.

我已经搜索了很多关于此的内容,但找不到解决方案.

更新

在滑块更改事件中:

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

在页面加载时:

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

o

解决方案

如果你想实现 Tap (Touch) 音量并控制它的音量,你可以参考 Sound 官方文档.

<块引用>

UWP 提供了一个易于访问的声音系统,让您只需轻按一个开关"即可在整个应用中获得身临其境的音频体验.

ElementSoundPlayer 是 XAML 中的一个集成声音系统,打开时所有默认控件都会自动播放声音.

ElementSoundPlayer.State = ElementSoundPlayerState.On;

<块引用>

应用中的所有声音都可以通过音量控制变暗.但是,应用内的声音不能大于系统音量.

要设置应用音量级别,请调用:

ElementSoundPlayer.Volume = 0.5;

其中最大音量(相对于系统音量)为 1.0,最小为 0.0(基本静音).

更新

请尝试以下简单代码.

public MainPage(){this.InitializeComponent();ElementSoundPlayer.State = ElementSoundPlayerState.On;CurrentVol.Value = ElementSoundPlayer.Volume * 10;}private void Slider_ValueChanged(对象发送者,RangeBaseValueChangedEventArgs e){滑块滑块 = 发送方为滑块;double volumeLevel = slider.Value/10;ElementSoundPlayer.Volume = volumeLevel;}

Xaml

<Slider Name="CurrentVol" Maximum="10" ValueChanged="Slider_ValueChanged"/><Button Content="ClickMe"/></StackPanel>

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>

这篇关于UWP 触控音量控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆