I have an application that plays a wave file using the SoundPlayer class. However, when I publish the application in IIS, the file will not play. To use the SoundPlayer class I added a reference windows.dll, it may interfere?
public void PlaySound()
{
try
{
while (1 == 1)
{
List<string> distinctMusic = GetMusicFile.Distinct().ToList();
for (int i = 0; i < distinctMusic.Count; i++)
{
player.SoundLocation = distinctMusic[i];
player.Play();
Thread.Sleep(GetMusicDuration[i] * 1000);
player.Stop();
}
player.Dispose();
}
}
catch (Exception e)
{
//log.LogTxt(e.ToString());
}
}
Can anyone help me? Thx !
To play sound on a web page you will either need to use HTML5 audio control or embed Media Player control.
The direction you have takes will work in Windows applications but not on the web.
You don't need JavaScript as mentioned in another response.
http://www.w3schools.com/html/html5_audio.asp
Note: not all HTML5 browsers support wave file (IE for example), please refer to this link for compatibility
http://en.wikipedia.org/wiki/HTML5_Audio
There's no way of using C# in asp.net to play a sound on client-side (except Silverlight of course). You need to use a client-side technology, like javascript.
For instance this:
Playing audio with Javascript?
http://www.w3schools.com/html/html_sounds.asp