Search code examples
asp.netiissoundplayerplaysound

How to run a .wav in client. ASP.NET


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 !


Solution

  • 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

    <audio controls height="100" width="100">
      <source src="horse.mp3" type="audio/mpeg">
      <source src="horse.ogg" type="audio/ogg">
      <embed height="50" width="100" src="horse.mp3">
    </audio>