C#Windows Forms应用程序音量滑块
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了C#Windows Forms应用程序音量滑块,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1820字,纯文字阅读大概需要3分钟。
内容图文
![C#Windows Forms应用程序音量滑块](/upload/InfoBanner/zyjiaocheng/949/d3ddb0412a7b417cadef833a58e55e3d.jpg)
我有一个使用声音播放器播放.wav文件的应用程序,我进行了查找,但找不到改变其播放音量的方法.我要寻找的是通过以下方式独立更改文件的音量:程序或具有滑块,以在Windows音量混合器中更改窗口本身的音量.谢谢!
public void loadSound()
{
sp.Load();
sp.Play();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (BarTimer.Value < BarTimer.Maximum)
{
BarTimer.Value = BarTimer.Value + 1;
}
if(BarTimer.Value==BarTimer.Maximum)
{
loadSound();
timer1.Stop();
BarTimer.Value = BarTimer.Minimum;
}
}
解决方法:
我只在MSDN:Attenuating SoundPlayer Volume上找到它.
它使用waveOutGetVolume和waveOutSetVolume函数.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace VolumeControl
{
public partial class Form1 : Form
{
[DllImport("winmm.dll")]
public static extern int waveOutGetVolume(IntPtr hwo, out uint dwVolume);
[DllImport("winmm.dll")]
public static extern int waveOutSetVolume(IntPtr hwo, uint dwVolume);
public Form1()
{
InitializeComponent();
// By the default set the volume to 0
uint CurrVol = 0;
// At this point, CurrVol gets assigned the volume
waveOutGetVolume(IntPtr.Zero, out CurrVol);
// Calculate the volume
ushort CalcVol = (ushort)(CurrVol & 0x0000ffff);
// Get the volume on a scale of 1 to 10 (to fit the trackbar)
trackWave.Value = CalcVol / (ushort.MaxValue / 10);
}
private void trackWave_Scroll(object sender, EventArgs e)
{
// Calculate the volume that's being set. BTW: this is a trackbar!
int NewVolume = ((ushort.MaxValue / 10) * trackWave.Value);
// Set the same volume for both the left and the right channels
uint NewVolumeAllChannels = (((uint)NewVolume & 0x0000ffff) | ((uint)NewVolume << 16));
// Set the volume
waveOutSetVolume(IntPtr.Zero, NewVolumeAllChannels);
}
}
}
希望能有所帮助.
内容总结
以上是互联网集市为您收集整理的C#Windows Forms应用程序音量滑块全部内容,希望文章能够帮你解决C#Windows Forms应用程序音量滑块所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。