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. c++map用法

    #include<iostream> #include<algorithm> #include<map> using namespace std; void fun ...

  2. img的基线对齐问题

    http://blog.csdn.net/u011997156/article/details/44806523

  3. 碎碎念android eMMC【转】

    本文转载自:https://blog.csdn.net/Fybon/article/details/44242549 一./dev/blockroot@:/dev/block #ls bootdevi ...

  4. MongoDB NoSQL 常用指令

    查询 日期区间 db.<collections>.find({"service_name":"xxx"}).sort({ update_time:- ...

  5. Spring-Cache 注解 @Cacheable,@CachePut , @CacheEvict

    1.自动生成key @Bean public KeyGenerator keyGenerator() { return new KeyGenerator() { @Override public Ob ...

  6. 【做题】CF285E. Positions in Permutations——dp+容斥

    题意:求所有长度为\(n\)的排列\(p\)中,有多少个满足:对于所有\(i \,(1 \leq i \leq n)\),其中恰好有\(k\)个满足\(|p_i - i| = 1\).答案对\(10^ ...

  7. 【Finchley】【新特性】Spring Cloud Finchley 新特性

    Finchley 正式版的发布貌似经历了相当长的时间,这次的重大发布主要带来了以下 4 项重大更新. 重大更新 1.新增 Spring Cloud Gateway 组件 Spring Cloud Ga ...

  8. oracle 之 包,包体创建和使用案例

    先创建包,再创建包体---------------创建包体--------------------- create or replace package body pkg_yygl_service I ...

  9. JAVA JDBC 增删改查简单例子

    1.数据库配置文件jdbc.properties driver=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/test username= ...

  10. Matconvnet 的一些记录

    Matconvnet 的一些记录 Example code from ADNet: Action-Decision Networks for Visual Tracking with Deep Rei ...