0

I have made an app to controll the volume of my pc it is setting the slider's value to the volume of the pc when i am starting the app but i want it to update it's value if i change the volume using the keys or the windows volume controller.

using NAudio.CoreAudioApi;

namespace Launcher
{ 
    public partial class Media : Window
    {
        public Media()
        {
            InitializeComponent();
            var deviceEnumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator();
            var device = deviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
            Vols.Value = device.AudioEndpointVolume.MasterVolumeLevelScalar;
            vol.Content = Math.Round((float)Vols.Value, 2) * 100;
        }
        private void vols_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            vol.Content = Math.Round((float)Vols.Value, 2) * 100;
        }

        private void VolSlider_ValueChanged_1(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            var deviceEnumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator();
            var device = deviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
            device.AudioEndpointVolume.MasterVolumeLevelScalar= (float)Vols.Value;
            vol.Content = Math.Round((float)Vols.Value, 2) * 100;
        }
    }
}

It basically changes the volume of my pc if i change the slider value and shows the volume in an label, and i want those values to be updated when the pc volume is modified.

0 Answers0