7 Replies Latest reply on Dec 17, 2013 11:21 AM by Brian Leathem

    Using a4j:mediaOutput to play .mp3 audio file . Running on Chome But No On FireFox.

    Haroon Foad Newbie

      Hi all,

      Can anyone provide me with an example of streaming an audio file .mp3 using a4j:mediaOutput?

      I have this code example but it works on chrome not on FireFox

      <?xml version='1.0' encoding='UTF-8' ?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:a4j="http://richfaces.org/a4j"
            xmlns:rich="http://richfaces.org/rich"
            xmlns:f="http://java.sun.com/jsf/core">
          <h:head>
              <title>Streaming Audio</title>
          </h:head>
          <h:body>
              <h1>Running media.mp3</h1>
      
      
              <h:form>
                  <a4j:mediaOutput element="object" cacheable="false" id="audio"
                                   createContent="#{audioBean.process}"
                                   mimeType="audio/mpeg" />
              </h:form>
      </h:body>
      </html>
      

       

       

      Audio Bean.java

       

      package mypack;
      
      import java.io.InputStream;
      import java.io.OutputStream;
      import java.net.URL;
      import java.net.URLConnection;
      import javax.faces.bean.ManagedBean;
      import javax.faces.bean.SessionScoped;
      
      
      /**
      *
      * @author hfoad
      */
      @ManagedBean
      @SessionScoped
      public class AudioBean {
      
      
      
      
          /**
           * Creates a new instance of AudioBean
           */
          public AudioBean() {
          }
      
      
          public void process(OutputStream outStream, Object data) throws Exception {
              URL url = new URL("http://localhost/ivr/media.mp3");
              URLConnection urlC = url.openConnection();
              InputStream in = urlC.getInputStream();
      
      
              byte[] buffer = new byte[in.available()];
              int read;
      
      
              while ((read = in.read(buffer)) != -1) {
              }
              outStream.write(buffer);
              outStream.flush();
              outStream.close();
      
      
          }
      }
      
      
      

       

      How to make it running on FireFox as it is running on Chome?

      Thank you all.