简体   繁体   English

在客户端(浏览器)的Java EE Web应用程序上播放音频

[英]Play Audio on Java EE web application on client side (browser)

We are trying to play audio on the client machine. 我们正在尝试在客户端计算机上播放音频。 It is a web application based on Java EE, wherein due to some event happening at server side, the client should ring a bell or something of that sort. 它是基于Java EE的Web应用程序,其中由于服务器端发生某些事件,客户端应按钟声或类似的声音。

I am not aware of any such thing. 我不知道有任何这样的事情。 Alternative is to use 替代方法是使用

Html5 HTML5

, but then it's become browser dependent that the browser should be Html5 compatible. ,但随后该浏览器就必须与Html5兼容,这取决于浏览器。 I cannot enforce this requirement onto the client. 我无法将此要求强加给客户端。

I went through 我经历了

Red5 红色5

but found it not very useful.. 但发现它不是很有用。

Please advise 请指教

There are two parts to the problem: 这个问题有两个部分:

  • playing sound in a browser 在浏览器中播放声音
  • the browser being notified of events on the server 向浏览器通知服务器上的事件

For playing sounds, and to support a wide range of browsers, you have a number of options. 为了播放声音并支持各种浏览器,您有多种选择。 HTML5 <audio> tag and Plugins (Flash, Java applet). HTML5 <audio>标签和插件(Flash,Java applet)。 You could also use a Javascript library such as Yahoo Media Player to make this easier. 您还可以使用Java库(例如Yahoo Media Player)来简化此过程。 A starter is here . 一个起动器在这里

The second problem is how to notify clients when an event on the server occurs. 第二个问题是如何在服务器上发生事件时通知客户端。 This could be done with AJAX calls polling the server. 这可以通过轮询服务器的AJAX调用来完成。 Since you are using Java EE, this could be made a bit more efficient using Asynchronous Servlets . 由于您使用的是Java EE,因此可以使用Asynchronous Servlets使其效率更高。 You could also go down the WebSocket path with this as well, though there can be issues through proxy servers with this. 您也可以与此同时沿WebSocket路径运行,尽管与此相关的代理服务器可能会出现问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM