What cause my C#.NET program to mute sound??

Here is the Sound object someone wrote for me on EE that works great, but causes the Windows sound to mute, effectively halting my program's usefulness.

    public class Sound
      {
            private byte[] m_soundBytes;
            private string m_fileName;        

            private enum Flags
            {
                  SND_SYNC = 0x0000,  /* play synchronously (default) */
                  SND_ASYNC = 0x0001,  /* play asynchronously */
                  SND_NODEFAULT = 0x0002,  /* silence (!default) if sound not found */
                  SND_MEMORY = 0x0004,  /* pszSound points to a memory file */
                  SND_LOOP = 0x0008,  /* loop the sound until next sndPlaySound */
                  SND_NOSTOP = 0x0010,  /* don't stop any currently playing sound */
                  SND_NOWAIT = 0x00002000, /* don't wait if the driver is busy */
                  SND_ALIAS = 0x00010000, /* name is a registry alias */
                  SND_ALIAS_ID = 0x00110000, /* alias is a predefined ID */
                  SND_FILENAME = 0x00020000, /* name is file name */
                  SND_RESOURCE = 0x00040004  /* name is resource name or atom */
            }

            /*[DllImport("CoreDll.DLL", EntryPoint="PlaySound", SetLastError=true)]
            private extern static int WCE_PlaySound(string szSound, IntPtr hMod, int flags);

            [DllImport("CoreDll.DLL", EntryPoint="PlaySound", SetLastError=true)]
            private extern static int WCE_PlaySoundBytes (byte[] szSound, IntPtr hMod, int flags);*/

            [DllImport("winmm.DLL", EntryPoint="PlaySound", SetLastError=true)]
            private extern static int WCE_PlaySound(string szSound, IntPtr hMod, int flags);

            [DllImport("winmm.DLL", EntryPoint="PlaySound", SetLastError=true)]
            private extern static int WCE_PlaySoundBytes (byte[] szSound, IntPtr hMod, int flags);

            /// <summary>
            /// Construct the Sound object to play sound data from the specified file.
            /// </summary>
            public Sound (string fileName)
            {
                  m_fileName = fileName;
            }

            /// <summary>
            /// Construct the Sound object to play sound data from the specified stream.
            /// </summary>
            public Sound(Stream stream)    
            {
                  // read the data from the stream
                  m_soundBytes = new byte [stream.Length];
                  stream.Read(m_soundBytes, 0,(int)stream.Length);
            }

            /// <summary>
            /// Play the sound
            /// </summary>
            public void Play (Handles handles)
            {
            if (handles.AdjustVolume != null)
            {
                handles.AdjustVolume.SetVolume();
            }
                  // if a file name has been registered, call WCE_PlaySound,
                  //  otherwise call WCE_PlaySoundBytes
                  if (m_fileName != null)
                        WCE_PlaySound(m_fileName, IntPtr.Zero, (int) (Flags.SND_ASYNC | Flags.SND_FILENAME));
                  else
                        WCE_PlaySoundBytes (m_soundBytes, IntPtr.Zero, (int) (Flags.SND_ASYNC | Flags.SND_MEMORY));
            }

        public static void PlaySound(Handles handles, string fileName)
            {
                  Sound sound = new Sound( fileName );
            sound.Play(handles);
            }

        public static void RingBell( Handles handles, string soundName, int numRings, Condition condition )
        {
            RingBellTimer ringBellTimer = new RingBellTimer(handles, soundName);
            TimeSpan timeSpan = new TimeSpan(0, 0, 15);
            handles.TaskQueue.Add(new RepeatingFiniteTask(handles, ringBellTimer, timeSpan, numRings, condition));
        }
}

Does anyone have an idea why???  I urgently need a solution.

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.

SolutionsCSCommented:
(int) (Flags.SND_ASYNC or Flags.SND_NOSTOP) could help if a sound currently play.
But the method used here won't permit mixing with orther sound source.
try it instead... ;)

My.Computer.Audio.Play("Your sound file")
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 do not know how to access My.Computer.Audio.Play from within C#.NET.

Do you know??
0
newbiewebSr. Software EngineerAuthor Commented:
No, the addition of Flags.SND_NOSTOP did not help.  I already had Flags.SND_ASYNC.

0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

SolutionsCSCommented:
System.io.stream


see that reference.
http://msdn2.microsoft.com/en-us/library/cf1shcah.aspx
0
newbiewebSr. Software EngineerAuthor Commented:
In C# there is not System.io.stream.

And I don't know VB.  Can you suggest anything else I can try?
0
SolutionsCSCommented:
This also exist in c# if you look at the link i sent you

http://msdn2.microsoft.com/en-us/library/cf1shcah.aspx
0
SolutionsCSCommented:
Here is an alternative for you in c#
  public class WSounds
  {
    [DllImport("WinMM.dll")]
    public static extern bool  PlaySound(string fname, int Mod, int flag);
 
    // these are the SoundFlags we are using here, check mmsystem.h for more
    public int SND_ASYNC    = 0x0001;     // play asynchronously
    public int SND_FILENAME = 0x00020000; // use file name
    public int SND_PURGE    = 0x0040;     // purge non-static events
 
    public void Play(string fname, int SoundFlags)
    {
      PlaySound(fname, 0, SoundFlags);
    }
 
    public void StopPlay()
    {
      PlaySound(null, 0, SND_PURGE);
    }
  }
 
}

Open in new window

0
newbiewebSr. Software EngineerAuthor Commented:
When I call Play(), what do I use as a SoundFlags value??
0
newbiewebSr. Software EngineerAuthor Commented:
Do yo ukonw the Hex value for Flags.SND_NOSTOP??  maybe it's not defined in my object which is why it did not work??
0
SolutionsCSCommented:
SND_ASYNC, as before
0
SolutionsCSCommented:
oups and SND_FILENAME Too
SND_ASYNC or SND_ASYNC

0
newbiewebSr. Software EngineerAuthor Commented:
I do have the value for that SND_NOSTOP: 0x0010

But when I run the program it doews not override the Mute All checkbox.

Any ideas?  This is a real problem. Ay idea what could cause the Mute All to check itself automatically anyway??
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
Components

From novice to tech pro — start learning today.