登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

秒大刀 博客

好好学习 天天向上

 
 
 

日志

 
 
 
 

C# wav声音播放  

2008-05-01 17:59:29|  分类: C# |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

using System.Runtime.InteropServices;

 

namespace Ymz

{

     /// <summary>

     /// 声音播放辅助类

     /// </summary>

     /// <remarks>也可以参考System.Media.SoundPlayer来实现声音文件的播放</remarks>

     public static class SoundPlayer

     {

         [Flags]

         public enum PlaySoundFlags : int

         {

              /// <summary>

              /// play synchronously 同步

              /// </summary>

              SND_SYNC = 0x0000,

              /// <summary>

              /// play asynchronously 异步

              /// </summary>

              SND_ASYNC = 0x0001,

              /// <summary>

              /// silence (!default) if sound not found

              /// </summary>

              SND_NODEFAULT = 0x0002,

              /// <summary>

              /// pszSound points to a memory file

              /// </summary>

              SND_MEMORY = 0x0004, 

              /// <summary>

              /// loop the sound until next sndPlaySound

              /// </summary>

              SND_LOOP = 0x0008,

              /// <summary>

              /// don't stop any currently playing sound

              /// </summary>

              SND_NOSTOP = 0x0010, 

              /// <summary>

              /// don't wait if the driver is busy

              /// </summary>

              SND_NOWAIT = 0x00002000,

              /// <summary>

              /// name is a registry alias

              /// </summary>

              SND_ALIAS = 0x00010000,

              /// <summary>

              /// alias is a predefined ID

              /// </summary>

              SND_ALIAS_ID = 0x00110000,

              /// <summary>

              /// name is file name

              /// </summary>

              SND_FILENAME = 0x00020000,

              /// <summary>

              /// name is resource name or atom

              /// </summary>

              SND_RESOURCE = 0x00040004,

         }

         /// <summary>

         /// plays a sound specified by a file name, resource, or system event.

         /// </summary>

         /// <param name="szSound">

         /// Pointer to a null-terminated string that specifies the sound to play. If this parameter is NULL,

         /// any currently playing waveform sound is stopped. To stop a non-waveform sound, specify SND_PURGE

         /// in the fdwSound parameter.

         /// Three flags in fdwSound (SND_ALIAS, SND_FILENAME, and SND_RESOURCE) determine whether the name is

         /// interpreted as an alias for a system event, a file name, or a resource identifier. If none of these

         /// flags are specified, PlaySound searches the registry or the WIN.INI file for an association with the

         /// specified sound name. If an association is found, the sound event is played. If no association is found

         /// in the registry, the name is interpreted as a file name.

         /// </param>

         /// <param name="hMod">Handle to the executable file that contains the resource to be loaded. This parameter

         /// must be NULL unless SND_RESOURCE is specified in fdwSound. </param>

         /// <param name="flags">Flags for playing the sound. The following table shows the possible values. </param>

         /// <returns>TRUE indicates success. FALSE indicates failure.</returns>

         [DllImport("winmm")]

         public static extern bool PlaySound(string szSound, IntPtr hMod, PlaySoundFlags flags);

         /// <summary>

         /// plays a sound specified by a file name, resource, or system event.

         /// </summary>

         /// <param name="szSound">

         /// Pointer to a null-terminated string that specifies the sound to play. If this parameter is NULL,

         /// any currently playing waveform sound is stopped. To stop a non-waveform sound, specify SND_PURGE

         /// in the fdwSound parameter.

         /// Three flags in fdwSound (SND_ALIAS, SND_FILENAME, and SND_RESOURCE) determine whether the name is

         /// interpreted as an alias for a system event, a file name, or a resource identifier. If none of these

         /// flags are specified, PlaySound searches the registry or the WIN.INI file for an association with the

         /// specified sound name. If an association is found, the sound event is played. If no association is found

         /// in the registry, the name is interpreted as a file name.

         /// </param>

         /// <param name="flags">Flags for playing the sound. The following table shows the possible values. </param>

         /// <returns>TRUE indicates success. FALSE indicates failure.</returns>

         public static bool PlaySound(string szSound, PlaySoundFlags flags)

         {

              return PlaySound(szSound, IntPtr.Zero, flags);

         }

     }

}

  评论这张
 
阅读(2120)| 评论(1)

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018