winform 调用api播放mp3 不知道为什么如果另起线程来播放则出错
程序demo:
http://pan.baidu.com/s/1eQBUQcy
public string FileName
{
get
{
return mc.iName;
}
set
{
//ASCIIEncoding asc = new ASCIIEncoding();
try
{
TemStr = "";
TemStr = TemStr.PadLeft(127, Convert.ToChar(" "));
Name = "";
Name = Name.PadLeft(260, Convert.ToChar(" "));
mc.iName = value;
ilong = APIClass.GetShortPathName(mc.iName, Name, Name.Length);
Name = GetCurrPath(Name);
//Name = "open " + Convert.ToChar(34) + Name + Convert.ToChar(34) + " alias media";
Name = "open " + Convert.ToChar(34) + Name + Convert.ToChar(34) + " alias media";
ilong = APIClass.mciSendString("close all", TemStr, TemStr.Length, 0);
//这里的话单线程正常 而另起线程的话到这步则没有正确得到结果 参数都是一致的 怎么回事呢?
ilong = APIClass.mciSendString(Name, TemStr, TemStr.Length, 0);
ilong = APIClass.mciSendString("set media time format milliseconds", TemStr, TemStr.Length, 0);
mc.state = State.mStop;
}
catch
{
}
}
}
Edit: Perhaps a hidden form launched over new thread can reduce the work do be done. But you still need to receive callback from MCI to terminate the thread.
我觉得可能是这个原因,因为我在使用BackgroundWorker以及各种多线程方法以后,都无法成功播放声音
[解决办法]