Chinaunix首页 | 论坛 | 博客
  • 博客访问: 12375417
  • 博文数量: 1293
  • 博客积分: 13501
  • 博客等级: 上将
  • 技术积分: 17974
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-08 18:11
文章分类

全部博文(1293)

文章存档

2019年(1)

2018年(1)

2016年(118)

2015年(257)

2014年(128)

2013年(222)

2012年(229)

2011年(337)

分类: C#/.net

2015-02-26 10:36:23

    .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:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Media;

  10. namespace paly
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }

  18.         private void button1_Click(object sender, EventArgs e)
  19.         {
  20.             string fileName = Application.StartupPath + "\\Windows Ding.wav";
  21.             System.Media.SoundPlayer player = new System.Media.SoundPlayer(fileName);
  22.             player.Play();
  23.         }

  24.     }
  25. }


image

image

 

另附:Windows自带的声音文件目录

C:\Windows\Media

 

参考博客:

http://blog.csdn.net/lance_lot1/article/details/8202602

阅读(2340) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~