嗨 ,我已经编写了以下代码,但仅在音频文件离开“dataGridView1_CellClick”事件后播放一次。我想知道:
1) 我可以在活动中播放声音吗?
2) 我可以在不使用 “Player.settings.playCount”的情况下重复播放吗?因为这段代码不能在每个文件发布之前延迟。谢谢
我的代码是:
WMPLib.WindowsMediaPlayer Player = new WMPLib.WindowsMediaPlayer();
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
//...
//********** Play audio of Word
// sVoicePath = @"C:\4536.mp3"
sVoicePath = Application.StartupPath + dataGridView1.CurrentRow.Cells[4].Value.ToString();
PlayFile(sVoicePath);
//...
}
//*****************************
private void PlayFile(String url)
{
for (int i = 0; i < 3 ;i++)
{
System.Threading.Thread.Sleep(2000);
Player.URL = url;
Player.controls.play();
}
}
//*****************************
private void Player_PlayStateChange(int NewState)
{
if ((WMPLib.WMPPlayState)NewState ==
WMPLib.WMPPlayState.wmppsStopped)
{
//Actions on stop
}
}