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

99封情书 提交于 2019-12-25 07:36:11

问题


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 !


回答1:


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>



回答2:


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



来源:https://stackoverflow.com/questions/17221567/how-to-run-a-wav-in-client-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!