Professional Applications Programmers/Consultants برمجة واستشارات تطبيقات الإنترنت
Skip Navigation LinksHome » Code Library » Sound

Public general use code classes and xml files that we've compiled and used over the years:

Sound support class.

   1:  #if WINDOWS_FORM
   2:  using System;
   3:  using System.Runtime.InteropServices;
   4:   
   5:  namespace Ia.Cl.Model
   6:  {
   7:      ////////////////////////////////////////////////////////////////////////////
   8:   
   9:      /// <summary publish="true">
  10:      /// Sound support class.
  11:      /// </summary>
  12:      /// <remarks> 
  13:      /// Copyright � 2001-2015 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
  14:      ///
  15:      /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
  16:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  17:      ///
  18:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  19:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  20:      /// 
  21:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  22:      /// 
  23:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  24:      /// </remarks>
  25:      public abstract class Sound
  26:      {
  27:          ////////////////////////////////////////////////////////////////////////////
  28:   
  29:          /// <summary>
  30:          /// </summary>
  31:          public Sound() { }
  32:   
  33:          ////////////////////////////////////////////////////////////////////////////
  34:   
  35:          /// <summary>
  36:          ///
  37:          /// </summary>
  38:          [DllImport("WinMM.dll")]
  39:          public static extern bool PlaySound(string fname, int Mod, int flag);
  40:   
  41:          // these are the SoundFlags we are using here, check mmsystem.h for more 
  42:          private static int SND_PURGE = 0x0040; // purge non-static events 
  43:          private static int SND_ASYNC = 0x0001; // play asynchronously 
  44:          //private static int SND_SYNC = 0x0000; // play synchronously (default) 
  45:          private static int SND_NODEFAULT = 0x0002; // silence (!default) if sound not found 
  46:          //private static int SND_MEMORY = 0x0004; // pszSound points to a memory file 
  47:          //private static int SND_LOOP = 0x0008; // loop the sound until next sndPlaySound 
  48:          //private static int SND_NOSTOP = 0x0010; // don't stop any currently playing sound 
  49:          private static int SND_NOWAIT = 0x00002000; // don't wait if the driver is busy 
  50:          //private static int SND_ALIAS = 0x00010000; // name is a registry alias 
  51:          //private static int SND_ALIAS_ID = 0x00110000; // alias is a predefined ID 
  52:          private static int SND_FILENAME = 0x00020000; // name is file name 
  53:          //private static int SND_RESOURCE = 0x00040004; // name is resource name or atom 
  54:   
  55:          ////////////////////////////////////////////////////////////////////////////
  56:   
  57:          /// <summary>
  58:          ///
  59:          /// </summary>
  60:          public static void Play(string fname)
  61:          {
  62:              //StopPlay(); 
  63:              PlaySound(fname, 0, SND_ASYNC | SND_NODEFAULT | SND_FILENAME | SND_NOWAIT);
  64:          }
  65:   
  66:          ////////////////////////////////////////////////////////////////////////////
  67:   
  68:          /// <summary>
  69:          ///
  70:          /// </summary>
  71:          public static void Stop()
  72:          {
  73:              PlaySound(null, 0, SND_PURGE);
  74:          }
  75:   
  76:          ////////////////////////////////////////////////////////////////////////////
  77:          ////////////////////////////////////////////////////////////////////////////
  78:      }
  79:  }
  80:  #endif