Domanda

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 !

È stato utile?

Soluzione

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>

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top