C#基于UDP实现的P2P语音聊天工具

2019-12-30 10:57:56王冬梅
  • }   else 
  • {   FinalizeWaveFile();  
  • }   }  
  • void StopRecord()   {  
  • AllChangeBtn(btn_luyin, true);   AllChangeBtn(btn_stop, false);  
  • AllChangeBtn(btn_sendsound, true);   AllChangeBtn(btn_play, true);  
  •   //btn_luyin.Enabled = true;  
  • //btn_stop.Enabled = false;   //btn_sendsound.Enabled = true;  
  • //btn_play.Enabled = true;   if (waveIn != null)  
  • waveIn.StopRecording();   //Cleanup();  
  • }   private void Cleanup()  
  • {   if (waveIn != null)  
  • {   waveIn.Dispose();  
  • waveIn = null;   }  
  • FinalizeWaveFile();   }  
  • private void FinalizeWaveFile()   {  
  • if (writer != null)   {  
  • writer.Dispose();   writer = null;  
  • }   }  
  • //开始录音   private void btn_luyin_Click(object sender, EventArgs e)  
  • {   btn_stop.Enabled = true;  
  • btn_luyin.Enabled = false;   if (waveIn == null)  
  • {   CreateWaveInDevice();  
  • }   if (File.Exists(soundfile))  
  • {   File.Delete(soundfile);  
  • }    
  • writer = new WaveFileWriter(soundfile, waveIn.WaveFormat);   waveIn.StartRecording();