当我使用的代码是:
时,如何在不触及计算机主音量控制的情况下将应用程序中的声音静音/取消静音:My.Computer.Audio.Play(My.Resources.audio_here, AudioPlayMode.Background)
答案 0 :(得分:0)
查看winmm.dll中的waveOutSetVolume
和waveOutGetVolume
函数
Private Declare Function waveOutSetVolume Lib "winmm.dll" (ByVal uDeviceID As Integer, ByVal dwVolume As Integer) As Integer
Private Declare Function waveOutGetVolume Lib "winmm.dll" (ByVal uDeviceID As Integer, ByRef lpdwVolume As Integer) As Integer
根据目标计算机的操作系统版本,您可能需要考虑使用较新的MMDevice
和EndpointVolume
API。
答案 1 :(得分:0)
最后,我花了10个多小时尝试不同的选项,并将C ++和C#代码翻译成VB.net,最后这个代码似乎至少对我有用。亲自尝试
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Public Class Form1
<DllImport("winmm.dll")>
Public Shared Function waveOutSetVolume(ByVal h As IntPtr, ByVal dwVolume As UInteger) As Integer
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Show()
Dim keyValue As String 'disable web click sound
keyValue = "%SystemRoot%\Media\"
If Environment.OSVersion.Version.Major = 5 AndAlso Environment.OSVersion.Version.Minor > 0 Then
keyValue += "Windows XP Start.wav"
ElseIf Environment.OSVersion.Version.Major = 6 Then
keyValue += "Windows Navigation Start.wav"
Else
Return
End If
Dim key As RegistryKey = Registry.CurrentUser.OpenSubKey("AppEvents\Schemes\Apps\Explorer\Navigating\.Current", True)
key.SetValue(Nothing, "", RegistryValueKind.ExpandString)
Me.WebBrowser1.Navigate("https://www.youtube.com/some_video")
waveOutSetVolume(IntPtr.Zero, 0)
End Sub
结束班
答案 2 :(得分:0)
[DllImport("winmm.dll")]
private static extern int waveOutSetVolume(IntPtr hwo, uint dwVolume);
//mute application
private void mute(){
{
int NewVolume = 0; //set 0 to unmute
uint NewVolumeAllChannels = (((uint)NewVolume & 0x0000ffff) | ((uint)NewVolume << 16));
waveOutSetVolume(IntPtr.Zero, NewVolumeAllChannels);
}
//unmute application
private void unmute(){
{
int NewVolume = 65535; //set 65535 to unmute
uint NewVolumeAllChannels = (((uint)NewVolume & 0x0000ffff) | ((uint)NewVolume << 16));
waveOutSetVolume(IntPtr.Zero, NewVolumeAllChannels);
}