我有播放存储在一个ArrayList音符下面的播放方法:C#设定时间段和播放声音存储在一个ArrayList连续
public void Play(Duration d){
int duration = 1;
if (d == Duration.SemiBreve)
{
duration = 16;
}
else if (d == Duration.DotMin)
{
duration = 10;
}
else if (d == Duration.minim)
{
duration = 8;
}
else if (d == Duration.Crotchet)
{
duration = 4;
}
else if (d == Duration.Quaver)
{
duration = 2;
}
else if (d == Duration.SemiQuaver)
{
duration = 1;
}
player = new SoundPlayer();
player.SoundLocation = "pathToLocation";
//set timer
time = new Timer();
time.Tick += new EventHandler(clockTick);
time.Interval = duration * 150;
player.Play();
time.Start();
}
当我打电话的一个按钮的方法:
private void PlayButton_Click(object sender, EventArgs e)
{
//Loops through the collection and plays each note one after the other
foreach (MusicNote music in this.staff.Notes)
{
music.Play(music.Dur)
}
}
只有最后一个音符被播放。使用PlaySync()播放所有音符,但持续时间无法识别。我也尝试使用这样的线程:
foreach (MusicNote music in this.staff.Notes)
{
Thread t = new Thread(playMethod=>music.Play(music.Dur));
t.Start();
t.Join();
}
但它也不起作用。有关如何让文件像PlaySync一样连续播放,但使用其设定的时间长度的任何建议?
您必须添加一些逻辑来一次播放一个音符。尝试让它工作,以便在点击按钮后播放一个音符。然后添加计时器。 – CodingBarfield 2011-12-27 10:55:00