用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 ...
随机推荐
- centos 设置时间为北京时间
https://www.cnblogs.com/biaopei/p/7730462.html
- 我的QML
1.键盘加Text import QtQuick 2.7 import QtGraphicalEffects 1.0 Rectangle{ width:; height:; color:"# ...
- Eclipse的Servers视图中无法添加Tomcat
问题:Eclipse的Servers视图中无法添加Tomcat,其中ServerName是被置为灰色的,无法编辑,如下图所示: 解决步骤: 关闭Eclipse 找到Eclipse的工作区间,这里假设命 ...
- SpringBoot 使用validation数据校验
后端对数据进行验证 添加包 hibernate-validator <!-- https://mvnrepository.com/artifact/org.hibernate.validator ...
- How can I move a MySQL database from one server to another?
My favorite way is to pipe a sqldump command to a sql command. You can do all databases or a specifi ...
- 【转载】C++宏定义详解
摘自:http://blog.chinaunix.net/uid-21372424-id-119797.html C++宏定义详解 2011-02-14 23:33:24 分类: C/C++ ...
- pyqt笔记1模块 信号和插槽
资料 PyQt5图形界面编程 PyQt5指南 模块 PyQt5本身拥有超过620个类和6000函数及方法. QtCore模块涵盖了包的核心的非GUI功能,此模块被用于处理程序中涉及到的 time.文件 ...
- C语言: 从 CodeBlocks 到 Microsoft Visual Studio 2017
开学到现在寒假,学习了一个学期的C语言,同时也已然用了大半年的 CodeBlocks 来写 C/C++ 程序.CodeBlocks 是写 C/C++ 语言的程序最轻量的IDE(集成开发环境),在 C ...
- _attribute_character
职业属性控制表 comment 备注 classI ...
- 【BZOJ】3295: [Cqoi2011]动态逆序对
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3295 mamaya,弱鸡xrdog终于会写树套树啦.... 将树状数组中每一个节点看成一棵 ...