用C#实现多种方式播放Wav声音
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声音的更多相关文章
- wince mobile环境下播放WAV声音
[DllImport("coredll", EntryPoint = "PlaySound")] public static extern i ...
- MmSystem播放Wav格式声音
//MmSystem播放Wav格式声音 //MmSystem 支持 *.wav声音格式 snd ->SoundRecorderuses MmSystem; //引用MmSystem//播放系统声 ...
- 通过WinAPI播放PCM声音
在Windows平台上,播放PCM声音使用的API通常有如下两种. waveOut and waveIn:传统的音频MMEAPI,也是使用的最多的 xAudio2:C++/COM API,主要针对游戏 ...
- IOS音频1:之采用四种方式播放音频文件(一)AudioToolbox AVFoundation OpenAL AUDIO QUEUE
本文转载至 http://blog.csdn.net/u014011807/article/details/40187737 在本卷你可以学到什么? 采用四种方法设计应用于各种场合的音频播放器: 基于 ...
- C++播放wav音乐和音效
1. #include <mmsystem.h>#pragma comment(lib,"winmm.lib")PlaySound(TEXT("c:\\te ...
- 用 Qt 的 QAudioOutput 类播放 WAV 音频文件
用 Qt 的 QAudioOutput 类播放 WAV 音频文件 最近有一个项目,需要同时控制 4 个声卡播放不同的声音,声音文件很简单就是没有任何压缩的 wav 文件. 如果只是播放 wav 文件, ...
- 8086汇编语言 调用声卡播放wav文件(sound blaster)
开更 大概最后做了一个能播放无损音乐(无压缩.不需解码)的播放器 原理是基于dosbox的模拟声卡,通过硬件之间的相互通讯做到的 关于详细内容接下来再讲. 一.从dosbox入手 我们知道cpu可以直 ...
- [C#] NAudio 库的各种常用使用方式: 播放 录制 转码 音频可视化
概述 在 NAudio 中, 常用类型有 WaveIn, WaveOut, WaveStream, WaveFileWriter, WaveFileReader 以及接口: IWaveProvider ...
- Java多种方式读文件,追加文件内容,等对文件的各种操作
一.多种方式读文件内容. 1.按字节读取文件内容 2.按字符读取文件内容 3.按行读取文件内容 4.随机读取文件内容 import java.io.BufferedReader; import jav ...
随机推荐
- fatal: [db01]: FAILED! => {"changed": false, "msg": "The PyMySQL (Python 2.7 and Python 3.X) or MySQL-python (Python 2.X) module is required."}
centos7.5 使用ansible中的role安装mariadb创建用户报错 错误: [root@m01 roles]# ansible-playbook site.yml TASK [mysql ...
- topcoder srm 707 div1
1 构造一个棋盘,长宽n,m不超过50,每个格子为障碍或者非障碍两种,使得从(0,0)到(n-1,m-1)的最短路为给定的值k. 思路:如果k小于等于98,那么一定存在没有障碍的棋盘满足要求.否则,最 ...
- Web操作web.config
1.引用System.Configuration.DLL 2.引用命名空间System.Configuration和System.Web.Configuration 3.上代码 // 使用指定的虚拟路 ...
- EControl的安装
EControl提供了运行期在窗体上进行界面设计的能力,手上的控件包是Delphi2010版的,在xe6下安装出现了一系列问题,弄了一晚上,总算搞定. 1.编译zDesign14.bpl包,修改DSN ...
- Python3基础 list list()生成空列表
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- 如何生成指定架构的Linux内核默认配置文件
答: make ARCH=<cpu architecture> defconfig 举例如下: make ARCH=arm64 defconfig (编译系统将会去目录arch/arm64 ...
- P3178 [HAOI2015]树上操作
P3178 [HAOI2015]树上操作 思路 板子嘛,其实我感觉树剖没啥脑子 就是debug 代码 #include <bits/stdc++.h> #define int long l ...
- 永久修改VS include目录
原文:https://blog.csdn.net/sysprogram/article/details/49214727 VS2008在选项里可以设置全局的Include目录和Lib目录, 但是VS2 ...
- iis6-0 cve-2017-7269 批量验证脚本
代码地址 import subprocess f = open('ips.txt', 'r') flines = f.readlines() vulnsrvs = 0 i = 1 for line i ...
- html 之 padding,margin
margin:对象挤压外界 padding:对象挤压自身 例如: td使用margin 对table而言没有任何效果,但使用padding是对table内部的挤压,若是table空间不够,则会扩大ta ...