c#

位置:IT落伍者 >> c# >> 浏览文章

C# 多种方式播放Wav声音


发布日期:2018年07月05日
 
C# 多种方式播放Wav声音

using System;

using SystemCollectionsGeneric;

using SystemComponentModel;

using SystemData;

using SystemDrawing;

using SystemText;

using SystemWindowsForms;

using SystemMedia;

using SystemResources;

using SystemIO;

namespace SoundPlayerApp

{

public partial class Form : Form

{

private SoundPlayer simpleSound;

public Form()

{

InitializeComponent();

}

private void button_Click(object sender EventArgs e)

{

OpenFileDialog OpenFileDialog = new OpenFileDialog();

OpenFileDialogFilter = Wav文件(*wav)|*wav;

if (OpenFileDialogShowDialog() == DialogResultOK)

{

simpleSound = new SoundPlayer(OpenFileDialogFileName);

simpleSoundPlay();

}

}

private void button_Click(object sender EventArgs e)

{

OpenFileDialog OpenFileDialog = new OpenFileDialog();

OpenFileDialogFilter = Wav文件(*wav)|*wav;

if (OpenFileDialogShowDialog() == DialogResultOK)

{

simpleSound = new SoundPlayer(OpenFileDialogFileName);

simpleSoundPlayLooping();

}

}

private void button_Click(object sender EventArgs e)

{

if (simpleSound != null) simpleSoundStop();

}

private void button_Click(object sender EventArgs e)

{

simpleSound = new SoundPlayer(PropertiesResourcesbig);

simpleSoundPlay();

}

private void button_Click(object sender EventArgs e)

{

simpleSound = new SoundPlayer(PropertiesResourcesbig);

simpleSoundPlayLooping();

}

private void button_Click(object sender EventArgs e)

{

if (simpleSound != null) simpleSoundStop();

}

private void button_Click(object sender EventArgs e)

{

switch (comboBoxText)

{

case 星号(错误):

SystemSoundsAsteriskPlay();

break;

case 默认响声(叮当声):

SystemSoundsBeepPlay();

break;

case 感歎号(惊歎号):

SystemSoundsExclamationPlay();

break;

case 关键性停止(关键性终止):

SystemSoundsHandPlay();

break;

case 问题:

SystemSoundsQuestionPlay();

break;

}

}

private void button_Click(object sender EventArgs e)

{

ResourceManager rm = ResourceManagerCreateFileBasedResourceManager(SoundResource ApplicationStartupPath null);//资源文件不带扩展名称

byte[] buffer = (byte[])rmGetObject(Soundwav);

FileStream FS = new FileStream(Soundwav FileModeCreate);//新建文件

BinaryWriter BWriter = new BinaryWriter(FS);//以二进制打开文件流

BWriterWrite(buffer bufferLength);//从资源文件读取声音文件内容写入到一个声音文件中

BWriterClose();

FSClose();

simpleSound = new SoundPlayer(Soundwav);

simpleSoundPlay();

}

private void button_Click(object sender EventArgs e)

{

ResourceManager rm = ResourceManagerCreateFileBasedResourceManager(SoundResource ApplicationStartupPath null);//资源文件不带扩展名称

byte[] buffer = (byte[])rmGetObject(Soundwav);

FileStream FS = new FileStream(Soundwav FileModeCreate);//新建文件

BinaryWriter BWriter = new BinaryWriter(FS);//以二进制打开文件流

BWriterWrite(buffer bufferLength);//从资源文件读取声音文件内容写入到一个声音文件中

BWriterClose();

FSClose();

simpleSound = new SoundPlayer(Soundwav);

simpleSoundPlayLooping();

}

private void button_Click(object sender EventArgs e)

{

if (simpleSound != null) simpleSoundStop();

}

}

}

               

上一篇:趣味理解ADO.NET对象模型

下一篇:C#.NET通过Socket实现平行主机之间网络通讯