我有一个能够播放和停止waf文件的按钮。 在处理程序按钮的方法,我有c#播放停止wav文件
if (button.Text="play")
{
..filepath of the wav file
wav.play();
button.txt="stop"
}
else{
wav.stop();
button.Text="play"
}
但当调试那张否则WAV是空的,所以我有一个空exception.where我错了?
我有一个能够播放和停止waf文件的按钮。 在处理程序按钮的方法,我有c#播放停止wav文件
if (button.Text="play")
{
..filepath of the wav file
wav.play();
button.txt="stop"
}
else{
wav.stop();
button.Text="play"
}
但当调试那张否则WAV是空的,所以我有一个空exception.where我错了?
你在else情况下给出wavv
而不是wav
,所以它可能会使它为空。
尝试这样做,
if (button.txt="play")
{ //..filepath of the wav file
if(wav != null)
{
wav.play();
button.txt="stop";
}
}
else
{
if(wav != null)
{
wav.stop(); //replaced wavv to wav
button.txt="play"
}
}
在你的代码,它看起来像你的声明,并在IF部分, 所以不会在其他部分可初始化WAV。你应该在if ... else 之外声明wav,然后使用wav.stop();
//declare wav variable here
if (button.Text="play")
{
if(wav != null)
{
//filepath of the wav file
wav.play();
button.txt="stop";
}
}
else{
if(wav != null)
{
wav.stop();
button.txt="play";
}
}
我认为这将有助于你...
什么是'wav'?它在哪里定义和初始化?请发布更多代码。 – 2011-04-28 11:56:44
你能否提供完整的buttin点击处理程序代码? – 2011-04-28 11:57:03
添加初始化wav对象的代码。除此之外,请在调用play()之前检查wav对象是否不为null – Yanshof 2011-04-28 11:57:21