【问题标题】:How to run a .wav in client. ASP.NET如何在客户端运行 .wav。 ASP.NET
【发布时间】:2013-06-21 03:00:51
【问题描述】:

我有一个使用 SoundPlayer 类播放波形文件的应用程序。但是,当我在 IIS 中发布应用程序时,该文件将无法播放。 要使用 SoundPlayer 类我添加了一个引用 windows.dll,它可能会干扰?

 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());
        }
    }

谁能帮帮我? 谢谢!

【问题讨论】:

标签: asp.net iis soundplayer playsound


【解决方案1】:

没有办法在 asp.net 中使用 C# 在客户端播放声音(当然 Silverlight 除外)。您需要使用客户端技术,例如 javascript。

例如:
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】:

    要在网页上播放声音,您需要使用 HTML5 音频控件或嵌入媒体播放器控件。

    您所采取的方向将适用于 Windows 应用程序,但不适用于 Web。

    您不需要另一个回复中提到的 JavaScript。

    http://www.w3schools.com/html/html5_audio.asp

    注意:并非所有的HTML5浏览器都支持wave文件(例如IE),兼容性请参考此链接

    http://en.wikipedia.org/wiki/HTML5_Audio

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-27
      • 2019-07-11
      • 2020-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多