using System;

   using System.Collections.Generic;

   using System.ComponentModel;

   using System.Data;

   using System.Drawing;

   using System.Text;

   using System.Windows.Forms;

   using System.Media;

   using System.Resources;

   using System.IO;

   namespace SoundPlayerApp

   {

   public partial class Form1 : Form

   {

   private SoundPlayer simpleSound;

   public Form1()

   {

   InitializeComponent();

   }

   private void button1_Click(object sender, EventArgs e)

   {

   OpenFileDialog OpenFileDialog1 = new OpenFileDialog();

   OpenFileDialog1.Filter = "Wav 文件(*.wav)|*.wav";

   if (OpenFileDialog1.ShowDialog() == DialogResult.OK)

   {

   simpleSound = new SoundPlayer(OpenFileDialog1.FileName);

   simpleSound.Play();

   }

   }

   private void button2_Click(object sender, EventArgs e)

   {

   OpenFileDialog OpenFileDialog1 = new OpenFileDialog();

   OpenFileDialog1.Filter = "Wav 文件(*.wav)|*.wav";

   if (OpenFileDialog1.ShowDialog() == DialogResult.OK)

   {

   simpleSound = new SoundPlayer(OpenFileDialog1.FileName);

   simpleSound.PlayLooping();

   }

   }

   private void button3_Click(object sender, EventArgs e)

   {

   if (simpleSound != null) simpleSound.Stop();

   }

   private void button4_Click(object sender, EventArgs e)

   {

   simpleSound = new SoundPlayer(Properties.Resources.big);

   simpleSound.Play();

   }

   
  private void button5_Click(object sender, EventArgs e)   {   simpleSound = new SoundPlayer(Properties.Resources.big);   simpleSound.PlayLooping();   }   private void button6_Click(object sender, EventArgs e)   {   if (simpleSound != null) simpleSound.Stop();   }   private void button7_Click(object sender, EventArgs e)   {   switch (comboBox1.Text)   {   case "星号(错误)":   SystemSounds.Asterisk.Play();   break;   case "默认响声(叮当声)":   SystemSounds.Beep.Play();   break;   case "感叹号(惊叹号)":   SystemSounds.Exclamation.Play();   break;   case "关键性停止(关键性终止)":   SystemSounds.Hand.Play();   break;   case "问题":   SystemSounds.Question.Play();   break;   }   }   private void button8_Click(object sender, EventArgs e)   {   ResourceManager rm = ResourceManager.CreateFileBasedResourceManager("SoundResource", Application.StartupPath, null);//资源文件不带扩展名称   byte[] buffer = (byte[])rm.GetObject("Sound.wav");   FileStream FS = new FileStream("Sound.wav", FileMode.Create);//新建文件   BinaryWriter BWriter = new BinaryWriter(FS);//以二进制打开文件流   BWriter.Write(buffer, , buffer.Length);//从资源文件读取声音文件内容,写入到一个声音文件中   BWriter.Close();   FS.Close();   simpleSound = new SoundPlayer("Sound.wav");   simpleSound.Play();   }   private void button9_Click(object sender, EventArgs e)   {   ResourceManager rm = ResourceManager.CreateFileBasedResourceManager("SoundResource", Application.StartupPath, null);//资源文件不带扩展名称   byte[] buffer = (byte[])rm.GetObject("Sound.wav");   FileStream FS = new FileStream("Sound.wav", FileMode.Create);//新建文件   BinaryWriter BWriter = new BinaryWriter(FS);//以二进制打开文件流   BWriter.Write(buffer, , buffer.Length);//从资源文件读取声音文件内容,写入到一个声音文件中   BWriter.Close();   FS.Close();   simpleSound = new SoundPlayer("Sound.wav");   simpleSound.PlayLooping();   }   private void button10_Click(object sender, EventArgs e)   {   if (simpleSound != null) simpleSound.Stop();   }   }   }

用C#实现多种方式播放Wav声音的更多相关文章

  1. wince mobile环境下播放WAV声音

     [DllImport("coredll", EntryPoint = "PlaySound")]         public static extern i ...

  2. MmSystem播放Wav格式声音

    //MmSystem播放Wav格式声音 //MmSystem 支持 *.wav声音格式 snd ->SoundRecorderuses MmSystem; //引用MmSystem//播放系统声 ...

  3. 通过WinAPI播放PCM声音

    在Windows平台上,播放PCM声音使用的API通常有如下两种. waveOut and waveIn:传统的音频MMEAPI,也是使用的最多的 xAudio2:C++/COM API,主要针对游戏 ...

  4. IOS音频1:之采用四种方式播放音频文件(一)AudioToolbox AVFoundation OpenAL AUDIO QUEUE

    本文转载至 http://blog.csdn.net/u014011807/article/details/40187737 在本卷你可以学到什么? 采用四种方法设计应用于各种场合的音频播放器: 基于 ...

  5. C++播放wav音乐和音效

    1.  #include <mmsystem.h>#pragma comment(lib,"winmm.lib")PlaySound(TEXT("c:\\te ...

  6. 用 Qt 的 QAudioOutput 类播放 WAV 音频文件

    用 Qt 的 QAudioOutput 类播放 WAV 音频文件 最近有一个项目,需要同时控制 4 个声卡播放不同的声音,声音文件很简单就是没有任何压缩的 wav 文件. 如果只是播放 wav 文件, ...

  7. 8086汇编语言 调用声卡播放wav文件(sound blaster)

    开更 大概最后做了一个能播放无损音乐(无压缩.不需解码)的播放器 原理是基于dosbox的模拟声卡,通过硬件之间的相互通讯做到的 关于详细内容接下来再讲. 一.从dosbox入手 我们知道cpu可以直 ...

  8. [C#] NAudio 库的各种常用使用方式: 播放 录制 转码 音频可视化

    概述 在 NAudio 中, 常用类型有 WaveIn, WaveOut, WaveStream, WaveFileWriter, WaveFileReader 以及接口: IWaveProvider ...

  9. Java多种方式读文件,追加文件内容,等对文件的各种操作

    一.多种方式读文件内容. 1.按字节读取文件内容 2.按字符读取文件内容 3.按行读取文件内容 4.随机读取文件内容 import java.io.BufferedReader; import jav ...

随机推荐

  1. [内核驱动] VS2012+WDK 8.0 Minifilter实现指定扩展名文件拒绝访问

    转载:http://blog.csdn.net/C0ldstudy/article/details/51585708 转载:http://blog.csdn.net/zj510/article/det ...

  2. 【python35.1--EasyGui界面】

    一.什么是EasyGUI EasyGUI是python中一个非常简单的GUI编程模块,不同于其他的GUI生成器,它不是事件驱动的,相反,所有的GUI交互都是通过简地函数调用就可以实现(意思是:函数调用 ...

  3. python&django 常见问题及解决方法

    0.python-dev安装(ubuntu) apt-get install  python-dev 1.Open(filename,mode) 报错实例: f = open('d:\Users\16 ...

  4. [翻译]使用VH和VW实现真正的流体排版

    前言 不像响应式布局,通过media query,设置几个变化点来适配,流体排版通过调整大小,适配所有设备宽度.这个方法可以使我们开发的网页,在几乎所有屏幕尺寸上都可以使用.但出于一些原因,它的使用率 ...

  5. android 系统 不深度休眠【转】

    本文转载自:https://blog.csdn.net/fmc088/article/details/80401405 1.分析解析 android系统有earlysuspend和suspend两种休 ...

  6. Why there is two completely different version of Reverse for List and IEnumerable?

    https://stackoverflow.com/questions/12390971/why-there-is-two-completely-different-version-of-revers ...

  7. cat查看文件以及sed查看指定行数

    https://unix.stackexchange.com/questions/288521/with-the-linux-cat-command-how-do-i-show-only-certai ...

  8. js 二叉树删除最大值和最小值

    //删除最小值function delMinNode (root){ if(!root) { return false; } var current = root; if (current.left ...

  9. Dependency Injection2

    IoC容器和Dependency Injection 模式   使用 Service Locator 依赖注入的最大好处在于:它消除了MovieLister类对具体 MovieFinder实现类的依赖 ...

  10. OpenLayers中的球面墨卡托投影

    最近看OpenLayers,研究到地图投影时找到官方的文档,就翻译了一下,由于英文能力差,翻译不好的地方,请看原文 原文地址:http://docs.openlayers.org/library/sp ...