Using an AxWindowsMediaPlayer in C#

I need to turn the mute to off on Windows XP, using C# and suspect that I need to instantiate an object similar to AxWindowsMediaPlayer.

Could someone please tell me what object in C#.NET I need to create for this and how to work with it??

thanks,
newbieweb
newbiewebSr. Software EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

monarch_ilhanCommented:
Use waveOutSetVolume function of winmm library.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
 
namespace VolumeControl
{
   public partial class Form1 : Form
   {
      [DllImport("winmm.dll")]
      public static extern int waveOutGetVolume(IntPtr hwo, out uint dwVolume);
 
      [DllImport("winmm.dll")]
      public static extern int waveOutSetVolume(IntPtr hwo, uint dwVolume);
 
      public Form1()
      {
         InitializeComponent();
         // By the default set the volume to 0
         uint CurrVol = 0;
         // At this point, CurrVol gets assigned the volume
         waveOutGetVolume(IntPtr.Zero, out CurrVol);
         // Calculate the volume
         ushort CalcVol = (ushort)(CurrVol & 0x0000ffff);
         // Get the volume on a scale of 1 to 10 (to fit the trackbar)
         trackWave.Value = CalcVol / (ushort.MaxValue / 10);
      }
 
      private void trackWave_Scroll(object sender, EventArgs e)
      {
         // Calculate the volume that's being set
         int NewVolume = ((ushort.MaxValue / 10) * trackWave.Value);
         // Set the same volume for both the left and the right channels
         uint NewVolumeAllChannels = (((uint)NewVolume & 0x0000ffff) | ((uint)NewVolume << 16));
         // Set the volume
         waveOutSetVolume(IntPtr.Zero, NewVolumeAllChannels);
      }
   }
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
newbiewebSr. Software EngineerAuthor Commented:
I won't need to present a scroll bar to change the volume, I just need to turn mute off before trying to play sound.  So I am trying to make an object for that purpose.  But I understand most (or all) of the object I included may be needless.

I started with your code and created a variabe for currentVolume to substitue for the variable trackWave.Value, but needed to typcast the uint to an int, but think that would totally change the values. Please take a look.
But all I really want is to turn mute off, and don't really think I need to be working with the volume.

Please take a look and let me know.  I have an urgent need to keep the mute off for a management system where the mute keeps getting set to on.

Thanks for the help,
newbieweb

    public partial class AdjustVolume
    {
        [DllImport("winmm.dll")]
        public static extern int waveOutGetVolume(IntPtr hwo, out uint dwVolume);

        [DllImport("winmm.dll")]
        public static extern int waveOutSetVolume(IntPtr hwo, uint dwVolume);

        uint currentVolume = 0;

        public AdjustVolume()
        {
            // By the default set the volume to 0
            uint CurrVol = 0;
            // At this point, CurrVol gets assigned the volume
            waveOutGetVolume(IntPtr.Zero, out CurrVol);
            // Calculate the volume
            ushort CalcVol = (ushort)(CurrVol & 0x0000ffff);
            // Get the volume on a scale of 1 to 10 (to fit the trackbar)
            currentVolume = (uint)CalcVol / (ushort.MaxValue / 10);
        }

        public void SetVolume()
        {
            // Calculate the volume that's being set
            int NewVolume = ((ushort.MaxValue / 10) * (int)currentVolume); <<<<< typecasted it to int
            // Set the same volume for both the left and the right channels
            uint NewVolumeAllChannels = (((uint)NewVolume & 0x0000ffff) | ((uint)NewVolume << 16));
            // Set the volume
            waveOutSetVolume(IntPtr.Zero, NewVolumeAllChannels);
        }
    }
0
monarch_ilhanCommented:
waveOutSetVolume(IntPtr.Zero, 0); mutes sound.. Do not waste time for type casting. it is Zero (0) for mute
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

newbiewebSr. Software EngineerAuthor Commented:
I want to unmute sound.

Is that what this does:

            waveOutSetVolume(IntPtr.Zero, NewVolumeAllChannels);

If so, please show me the code without typcasting to accomplish this.

thanks,
newbieweb
0
newbiewebSr. Software EngineerAuthor Commented:
what's the type of :

trackWave.Value

??

I am trying to create a variable inside the object to preseve the value returned by:

CalcVol / (ushort.MaxValue / 10);

0
newbiewebSr. Software EngineerAuthor Commented:
Don't worry about my past two questions.  I have you code compiling.  BUT the mute does not come off when I explicitly set the Mute All option in Windows.

My program somehow causes the mute All to become active, and I want my program to remove the Mute.

I hope this cal would do that:

waveOutSetVolume(IntPtr.Zero, NewVolumeAllChannels);

but it does not.  The value for NewVolumeAllChannels is:
4294639610

Thanks for the help,
newbieweb
0
monarch_ilhanCommented:
the below link is exactly what you want. (more than it) download sample code and get necessary part inside it

http://msdn2.microsoft.com/en-us/library/aa719104(VS.71).aspx

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.