Audio.cs :  » Build-Systems » CruiseControl.NET » ThoughtWorks » CruiseControl » CCTrayLib » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Build Systems » CruiseControl.NET 
CruiseControl.NET » ThoughtWorks » CruiseControl » CCTrayLib » Audio.cs
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace ThoughtWorks.CruiseControl.CCTrayLib{
  /// <summary>
  /// Summary description for Audio.
  /// </summary>
  public class Audio
  {
    ///<summary>
    ///Plays a sound from a byte array. 
    ///Note: If distortion or corruption of audio playback occurs, 
    ///try using synchronous playback, or save to a temp file and
    ///use the file-based option.
    ///</summary>
    public static int PlaySound (byte[] audio, bool bSynchronous, bool bIgnoreErrors)
    {
      return PlaySound (audio, bSynchronous, bIgnoreErrors, false, false, false);
    }

    ///<summary>
    ///Plays a sound from a byte array. 
    ///Note: If distortion or corruption of audio playback occurs, 
    ///try using synchronous playback, or save to a temp file and
    ///use the file-based option.
    ///</summary>
    public static int PlaySound (byte[] audio, bool bSynchronous, bool bIgnoreErrors,
                                 bool bNoDefault, bool bLoop, bool bNoStop)
    {
      const int SND_ASYNC = 1;
      const int SND_NODEFAULT = 2;
      const int SND_MEMORY = 4;
      const int SND_LOOP = 8;
      const int SND_NOSTOP = 16;
      int Snd_Options = SND_MEMORY;
      if (!bSynchronous)
      {
        Snd_Options += SND_ASYNC;
      }
      if (bNoDefault)
        Snd_Options += SND_NODEFAULT;
      if (bLoop)
        Snd_Options += SND_LOOP;
      if (bNoStop)
        Snd_Options += SND_NOSTOP;
      try
      {
        return PlaySound (audio, 0, Snd_Options);
      }
      catch (Exception)
      {
        if (!bIgnoreErrors)
        {
          throw;
        }
        else
        {
          return 0;
        }
      }
    }

    public static int PlaySound (string sSoundFile, bool bSynchronous, bool bIgnoreErrors)
    {
      return PlaySound (sSoundFile, bSynchronous, bIgnoreErrors, false, false, false);
    }

    public static int PlaySound (string sSoundFile, bool bSynchronous, bool bIgnoreErrors,
                                 bool bNoDefault, bool bLoop, bool bNoStop)
    {
      const int SND_ASYNC = 1;
      const int SND_NODEFAULT = 2;
      const int SND_LOOP = 8;
      const int SND_NOSTOP = 16;
      if (!System.IO.File.Exists (sSoundFile))
      {
        string WinDir = System.IO.Directory.GetParent (System.Environment.SystemDirectory).FullName;
        if (WinDir.Substring (WinDir.Length - 1, 1) != "\\")
          WinDir += "\\";
        if (System.IO.File.Exists (Application.StartupPath + "\\" + sSoundFile))
        {
          sSoundFile = Application.StartupPath + "\\" + sSoundFile;
        }
        else if (System.IO.File.Exists (Application.StartupPath + "\\" + sSoundFile + ".wav"))
        {
          sSoundFile = Application.StartupPath + "\\" + sSoundFile + ".wav";
        }
        else if (System.IO.File.Exists (WinDir + "media\\" + sSoundFile))
        {
          sSoundFile = WinDir + "media\\" + sSoundFile;
        }
        else if (System.IO.File.Exists (WinDir + "media\\" + sSoundFile + ".wav"))
        {
          sSoundFile = WinDir + "media\\" + sSoundFile + ".wav";
        }
        else if (!bIgnoreErrors)
        {
          throw new System.IO.FileNotFoundException ("Sound file doesn't exist.");
        }
      }
      int Snd_Options = 0;
      if (!bSynchronous)
      {
        Snd_Options = SND_ASYNC;
      }
      if (bNoDefault)
        Snd_Options += SND_NODEFAULT;
      if (bLoop)
        Snd_Options += SND_LOOP;
      if (bNoStop)
        Snd_Options += SND_NOSTOP;
      try
      {
        return sndPlaySoundA (sSoundFile, Snd_Options);
      }
      catch (Exception)
      {
        if (!bIgnoreErrors)
        {
          throw;
        }
        else
        {
          return 0;
        }
      }
    }

    [DllImport ("winmm.dll")]
    private static extern int sndPlaySoundA (string lpszSoundName, int uFlags);

    [DllImport ("winmm.dll")]
    private static extern int PlaySound (byte[] pszSound, Int16 hMod, long fdwSound);
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.