.net自带的有播放.wav格式音频文件的类:System.Media.SoundPlayer,只要调用这个类就可以了。
代码如下:
string path = “....../sound.wav”;//.wav音频文件路径
System.Media.SoundPlayer player = new System.Media.SoundPlayer(path);
player.Play();//简单播放一遍
player.PlayLooping();//循环播放
player.PlaySync();//另起线程播放
上面三种调用方法,只要调用任意一个就能播放。
JUST FOR TEST:
-
using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Drawing;
-
using System.Linq;
-
using System.Text;
-
using System.Windows.Forms;
-
using System.Media;
-
-
namespace paly
-
{
-
public partial class Form1 : Form
-
{
-
public Form1()
-
{
-
InitializeComponent();
-
}
-
-
private void button1_Click(object sender, EventArgs e)
-
{
-
string fileName = Application.StartupPath + "\\Windows Ding.wav";
-
System.Media.SoundPlayer player = new System.Media.SoundPlayer(fileName);
-
player.Play();
-
}
-
-
}
- }
另附:Windows自带的声音文件目录
C:\Windows\Media
参考博客: