iam製作一個應用程序,當一個鍵被關閉時播放聲音,當鍵被釋放時聲音立即停止。Key down無限循環
我發現的問題是,如果按下某個鍵,它會播放它的第一個毫秒,然後無限循環直到您釋放該鍵。
代碼IAM目前使用的是以下幾點:
public class Foo
{
public static int GetStream1(string path)
{
return Bass.BASS_StreamCreateFile(path, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_PRESCAN);
}
public static int GetStream2(string path)
{
return Bass.BASS_StreamCreateFile(path, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_PRESCAN);
}
}
protected override void OnKeyDown(KeyEventArgs e)
{
Bass.BASS_Init(1, 44100, BASSInit.BASS_DEVICE_DEFAULT, this.Handle);
Bass.BASS_Init(2, 44100, BASSInit.BASS_DEVICE_DEFAULT, this.Handle);
if (e.KeyCode == Keys.D1)
{
if (beatload1.Text == "Waiting 01.wav")
{
MessageBox.Show("No beat loaded");
return;
}
Beat1.Image = Beatpadpc.Properties.Resources.white_square_button;
try
{
Bass.BASS_SetDevice(1);
Bass.BASS_ChannelPlay(Foo.GetStream1(path1.Text), false);
}
catch (FileNotFoundException)
{
MessageBox.Show("File has been moved." + "\n" + "Please relocate it now!");
}
}
if (e.KeyCode == Keys.D2)
{
if (beatload2.Text == "Waiting 02.wav")
{
MessageBox.Show("No beat loaded");
return;
}
Beat2.Image = Beatpadpc.Properties.Resources.white_square_button;
try
{
Bass.BASS_SetDevice(2);
Bass.BASS_ChannelPlay(Foo.GetStream2(path2.Text), false);
}
catch (FileNotFoundException)
{
MessageBox.Show("File has been moved." + "\n" + "Please relocate it now!");
}
}
}
private void Window_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.D1)
{
Beat1.Image = Beatpadpc.Properties.Resources.black_square_button;
Bass.BASS_StreamFree(Foo.GetStream1(path1.Text));
Bass.BASS_SetDevice(1);
Bass.BASS_Free();
}
if (e.KeyCode == Keys.D2)
{
Beat2.Image = Beatpadpc.Properties.Resources.black_square_button;
Bass.BASS_StreamFree(Foo.GetStream2(path2.Text));
Bass.BASS_SetDevice(2);
Bass.BASS_Free();
}
}
那麼,有沒有在他們得到循環永遠在同一時間玩1個或多個聲音的方法嗎?
何塞,當你決定你有一個你滿意的答案時,你應該把它標記爲在左邊接受的答案,在表決之下投票和投票下箭頭。只有你,原始的海報,可以標記答案被接受。另外,當你這樣做的時候,它給了這個人更多的聲望點數(與你的名字相關的點數,你現在的數字是63) – philologon