|
本人C#新手,前些天在DirectX基础上用C#写了个录音软件,但是不知为什么不能够第二次录音,就是在结束第一次录音后只有关闭后重新调试才能够再次录音,否则会出现异常。怎么样才能够不关闭调试情况下再次录音?using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using Microsoft.DirectX;
using Microsoft.DirectX.DirectSound;
namespace SoundRecord
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
label2.Text = "录音状态—准备录音";
}
private SoundRecord recorder = new SoundRecord();
int hourStart, minuteStart, secondStart;////用于存储开始时刻的时分秒
private void btnStart_Click(object sender, EventArgs e)
{
hourStart = DateTime.Now.Hour; ////获取开始时刻的系统当前时间
minuteStart = DateTime.Now.Minute;
secondStart = DateTime.Now.Second;
string wavfile = "test.wav";
recorder.SetFileName(wavfile);
recorder.RecStart();////录音开始
timer1.Start();////计时开始
}
private void btnStop_Click(object sender, EventArgs e)
{
timer1.Stop();////计时结束
label2.Text = "录音状态—录音结束";
try
{
recorder.RecStop();////录音结束
}
catch (Exception ex)
{
MessageBox.Show("请不要直接或者连续点击停止按钮!");
return;
}
recorder = null;
}
private void timer1_Tick(object sender, EventArgs e)
{
int i1, i2, i3;
i1 = DateTime.Now.Hour - hourStart;
i2 = DateTime.Now.Minute - minuteStart;
i3 = DateTime.Now.Second - secondStart;
if (i3 < 0)
{
i3 = i3 + 60;
i2 = i2 - 1;
}
label2.Text = "录音状态—正在录音:" + i1.ToString() + ":" + i2.ToString() + ":" + i3.ToString();
}
}
}
还有个SoundRecord.cs文件(在网上下载,太长,此处放不下了),其中录音开始和停止都是在这里面的,希望大神能够指点啊!
|
|