Link to home
Start Free TrialLog in
Avatar of curiouswebster
curiouswebsterFlag for United States of America

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of monarch_ilhan
monarch_ilhan
Flag of Türkiye image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of curiouswebster

ASKER

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);
        }
    }
waveOutSetVolume(IntPtr.Zero, 0); mutes sound.. Do not waste time for type casting. it is Zero (0) for mute
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
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);

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
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