熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

C# 多種方式播放Wav聲音

2013-11-13 09:52:15  來源: .NET編程 

  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();

  }

  }

  }


From:http://tw.wingwit.com/Article/program/net/201311/11808.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.