首页 新闻 赞助 找找看

大家帮忙看看,这段代码哪里错了

0
悬赏园豆:5 [已关闭问题] 关闭于 2011-04-11 18:14

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;

问题补充: 经过修改,能显示结束时间了,可是不管怎样调试,就是不会响,这是怎么回事
青石的主页 青石 | 初学一级 | 园豆:160
提问于:2011-04-10 17:49
< >
分享
所有回答(2)
0
TimeSpan ts = new TimeSpan(long.Parse(strLength) * 1000);

 调试看看这个strLength有没有值或是类型能不能被转换为long类型!

Chenkun | 园豆:806 (小虾三级) | 2011-04-10 20:27
好像strLength没有值
支持(0) 反对(0) 青石 | 园豆:160 (初学一级) | 2011-04-10 23:12
没有值当然会出错,你上面的strLength =buffer.ToString().PadLeft (8, ' ').Substring(0,8); 这段程序的问题!你自己调试看看就明白了
支持(0) 反对(0) Chenkun | 园豆:806 (小虾三级) | 2011-04-11 15:02
0

strLength没有值,当然错了

梅莲芳 | 园豆:669 (小虾三级) | 2011-04-11 13:59
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册