Changing the volume moves the slider, but not the audio output

I have a slider and a webbrowser object in my form and moving, it should change the volume, however it moves the slider as shown here: Slider does move, but sound output doesn't change

but it does not change the actual output of the volume. This is probably due to the fact that I integrated the WebBrowser object and used Windows 7. When I manually move the slider (the one shown in the screenshot), the volume output changes. When playing a WAV file, the volume output changesbut not with a WebBrowser object.

I am using the following code:

Xaml

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Slider Minimum="0" Maximum="10" ValueChanged="ValueChanged"/>
    </Grid>
</Window>

WITH#

public partial class MainWindow
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
    {
        // Calculate the volume that being set
        double newVolume = ushort.MaxValue * e.NewValue / 10.0;

        uint v = ((uint) newVolume) & 0xffff;
        uint vAll = v | (v << 16);

        // Set the volume
        int retVal = NativeMethods.WaveOutSetVolume(IntPtr.Zero, vAll);

        Debug.WriteLine(retVal);
    }
}

static class NativeMethods
{
    [DllImport("winmm.dll", EntryPoint = "waveOutSetVolume")]
    public static extern int WaveOutSetVolume(IntPtr hwo, uint dwVolume);

}
+3
source share
2 answers

Try using MediaElement .

Then you can play on your radio as follows:

<MediaElement LoadedBehavior="Manual" x:Name="media" />

media.Source = new Uri(@"http://shoutcastinfo.radiostaddenhaag.com/stad.wax");
media.Play();

And change the volume with

<Slider Minimum="0" Maximum="1" ValueChanged="ValueChanged"/>

private void ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
    media.Volume = e.NewValue;
}

Windows, WPF , .

+2

, uint v = ((uint)newVolume) & 0xffff , uint v = (uint)newVolume .

-, MSDN waveOutSetVolume:

16 . , 4 , 0x4000, 0x4FFF 0x43BE 0x4000. waveOutGetVolume 16- waveOutSetVolume.

?

+1

All Articles