1. 插入一个width,height为0得播放器。并设置自动播放和循环播放为 true

2. using System.Runtime.InteropServices;
[DllImport("winmm.dll")]
public static extern long PlaySound(String fileName,long a,long b);

在事件中添加:
PlaySound("aa.wav",0,0); //aa.wav为声音文件

3.  [DllImport("winmm.dll")]
  public static extern long mciSendString(string lpstrCommand,string lpstrReturnString,long length,long hwndcallback);
  /// <summary>
  /// 播放音乐文件
  /// </summary>
  /// <param name="p_FileName">音乐文件名称</param>
  public static void PlayMusic(string p_FileName)
  {
   try
   {
    mciSendString(@"close " +p_FileName ,"                                  ",0,0);
    mciSendString(@"open " + p_FileName,"                                  ",0,0);
    mciSendString(@"play " + p_FileName ,"                                  ",0,0);
   }
   catch
   {
   }

  }
  
  /// <summary>
  /// 停止当前音乐播放
  /// </summary>
  /// <param name="p_FileName">音乐文件名称</param>
  public static void StopMusic(string p_FileName)
  {
   try
   {
    mciSendString(@"close " + p_FileName,"                                  ",0,0);
   }
   catch{}
  }
另外注意,由于文件路径和文件名中可能有空格,因此,文件名要用引号引起来,如:
filename="\"c:\\programe files\\a.mp3\"";

相关文章:

  • 2021-12-22
  • 2021-11-23
  • 2021-07-03
  • 2021-12-15
  • 2021-11-30
  • 2021-05-16
  • 2021-05-15
  • 2021-12-05
猜你喜欢
  • 2021-06-10
  • 2022-12-23
  • 2022-12-23
  • 2021-09-09
相关资源
相似解决方案