Search code examples
c#winformsvisual-studio-2010midiaxwindowsmediaplayer

AxWindowsMediaPlayer, Volume change is not occuring while playing Midi File


I am trying to change the volume of an AxWindowsMediaPlayer Object. Like this.

//Change Volume
private void VolumeTrackBar_ValueChanged(object sender, EventArgs e)
{
   if (MidiAxWindowsMediaPlayer != null && VolumeTrackBar != null)
       MidiAxWindowsMediaPlayer.settings.volume = VolumeTrackBar.Value*10;
}

If I place a break point inside that if statement, I can see it is executed as I intended. But the volume change is not reflected during playback. It always plays at the same volume,no matter if I change the volume before, during or after.

The TrackBar has a range from 0 to 10, so when I multiply it's value by 10, I will always get something in the range 0-100, which is the range needed by the AxWindowsMediaPlayer Object.


Solution

  • After searching and finding no solution (as well as other people having the same problem) I found a fix.

    Instead of referencing AxWMPLib, reference WMPLib

    Then create the Media Player Object Like so

    WMPLib.WindowsMediaPlayer MidiWindowsMediaPlayer = new WMPLib.WindowsMediaPlayer();
    

    ThisObject will allow volume changes to Midi Playback.