windows 7 + visual studio 2010 ,我从书上抄了一段代码,运行的时候总是提示input string was not in a correct format,就是在第一个timespan 那里,大家帮忙看看,是哪里错了
if (sFileName != null && sFileName.Trim() != "")
{
mciSendString("stop MP3File", null, 0, 0);
mciSendString("close MP3File", null, 0, 0);
}
sFileName = openFileDialog.FileName;
string strLength = "";
buffer = new StringBuilder(128);
mciSendString("open \"" + sFileName + "\"" + "type MPEGVideo alias MP3File", null, 0, 0);
mciSendString("set MP3File time format milliseconds", null, 0, 0);
mciSendString("set MP3File seek exactly on", null, 128, 0);
mciSendString("seek MP3File to start", null, 0, 0);
mciSendString("status MP3File length", buffer, 128, 0);
strLength =buffer.ToString().PadLeft (8, ' ').Substring(0,8);
if (strLength .Trim() !="")
{
progressBar.Minimum =0;
progressBar .Value=0;
progressBar.Maximum =int.Parse (strLength );
}
TimeSpan ts = new TimeSpan(long.Parse(strLength) * 1000);
lbCurrent.Text="00:00:00";
lbBegin.Text="00:00:00";
toolStripStatusLabel1 .Text="";
lbEnd.Text=ts.Hours.ToString("00:")+ts.Minutes.ToString("00:")+ts.Seconds .ToString("00");
timer.Enabled =false;
btnPlay.Enabled=true;
TimeSpan ts = new TimeSpan(long.Parse(strLength) * 1000);调试看看这个strLength有没有值或是类型能不能被转换为long类型!
strLength没有值,当然错了