I have an application that plays a particular song for a specified time, as the result of a select.
I can already play the songs, but I can not set a time duration.
public void PlaySound()
{
int i = 0;
foreach (string musicFile in musicFiles)
{
Thread thrStopMusic = new Thread(ThreadTimer);
player.SoundLocation = musicFile;
musicExecuteTime = GetMusicDuration[i];
player.Play();
thrStopMusic.Start();
thrStopMusic.Abort();
i++;
}
}
public void ThreadTimer()
{
Thread.Sleep(musicExecuteTime * 1000);
StopSound();
}
im using SoundPlayer class.
i think you can just do something like this. Play()
uses a new thread to play the file so you should just need to 'pause' your thread for an amount of time before invoking Stop()
.
public void PlaySound()
{
int i = 0;
foreach (string musicFile in musicFiles)
{
player.SoundLocation = musicFile;
player.Play();
Thread.Sleep(1000 * GetMusicDuration[i])
player.Stop();
i++;
}
}