tiene tengo sonido solucionado servicios responde para dispositivo como arreglar c# .net audio

tengo - Cambiar el volumen de audio maestro de XP a Windows 8 en C#



servicios de audio no responde windows 10 (2)

Para Windows 7+:

Hay algunos problemas con la respuesta aceptada. Debido a que la página del proyecto de código se elimina, ahora no tiene contexto.

  1. Debes obtener NAudio de Nuget

  2. Reemplace el primero con el segundo

    Dispositivo MMDevice = DevEnum.GetDefaultAudioEndpoint (EDataFlow.eRender, ERole.eMultimedia);

    Dispositivo MMDevice = DevEnum.GetDefaultAudioEndpoint ((DataFlow) 0, (Rol) 1);

Solo un aviso rápido si se pierde tratando de corregir los errores con el código de respuesta aceptada.

Necesito algún método general para cambiar el volumen maestro de audio de Windows XP a Windows 8 en C # porque mi aplicación va a funcionar en esos sistemas operativos.

Ya probé http://www.geekpedia.com/tutorial176_Get-and-set-the-wave-sound-volume.html pero no funciona en Windows 8. Quizás debería funcionar en Windows XP.

De todos modos, necesito un enfoque compatible para hacerlo. ¿Cualquier pista?


Entonces mi solución es combinar 2 proyectos:

  1. Silenciar / activar sonido, cambiar el volumen principal en Windows 7 x64 con C #

  2. http://www.geekpedia.com/tutorial176_Get-and-set-the-wave-sound-volume.html

    El código final debería ser similar (usa el marco de NAudio)

    static class NativeMethods { [DllImport("winmm.dll", EntryPoint = "waveOutSetVolume")] public static extern int WaveOutSetVolume(IntPtr hwo, uint dwVolume); [DllImport("winmm.dll", SetLastError = true)] public static extern bool PlaySound(string pszSound, IntPtr hmod, uint fdwSound); } public static class MSWindowsFriendlyNames { public static string WindowsXP { get { return "Windows XP"; } } public static string WindowsVista { get { return "Windows Vista"; } } public static string Windows7 { get { return "Windows 7"; } } public static string Windows8 { get { return "Windows 8"; } } } public static class SistemVolumChanger { public static void SetVolume(int value) { if (value < 0) value = 0; if (value > 100) value = 100; var osFriendlyName = GetOSFriendlyName(); if (osFriendlyName.Contains(MSWindowsFriendlyNames.WindowsXP)) { SetVolumeForWIndowsXP(value); } else if (osFriendlyName.Contains(MSWindowsFriendlyNames.WindowsVista) || osFriendlyName.Contains(MSWindowsFriendlyNames.Windows7) || osFriendlyName.Contains(MSWindowsFriendlyNames.Windows8)) { SetVolumeForWIndowsVista78(value); } else { SetVolumeForWIndowsVista78(value); } } public static int GetVolume() { int result = 100; try { MMDeviceEnumerator DevEnum = new MMDeviceEnumerator(); MMDevice device = DevEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia); result = (int)(device.AudioEndpointVolume.MasterVolumeLevelScalar * 100); } catch (Exception) { } return result; } private static void SetVolumeForWIndowsVista78(int value) { try { MMDeviceEnumerator DevEnum = new MMDeviceEnumerator(); MMDevice device = DevEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia); device.AudioEndpointVolume.MasterVolumeLevelScalar = (float)value / 100.0f; } catch (Exception) { } } private static void SetVolumeForWIndowsXP(int value) { try { // Calculate the volume that''s being set double newVolume = ushort.MaxValue * value / 10.0; uint v = ((uint)newVolume) & 0xffff; uint vAll = v | (v << 16); // Set the volume int retVal = NativeMethods.WaveOutSetVolume(IntPtr.Zero, vAll); } catch (Exception) { } } private static string GetOSFriendlyName() { string result = string.Empty; ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Caption FROM Win32_OperatingSystem"); foreach (ManagementObject os in searcher.Get()) { result = os["Caption"].ToString(); break; } return result; } }

Actualización # 1. Año 2015 Básicamente usa el framework NAudio. Así que hoy en día algunos métodos y propiedades de NAudio tienen otros nombres.

Por ejemplo

eDataFlow.eRender ahora es DataFlow.Render

y

eRole.eMultimedia es Role.Multimedia