Clients play a sound problem

Category: Web Develop
 
whsw3394
2009-04-19 09:39:35

Sponsored Links
I recently encountered a problem, specifically that:

customer requirements: Open the page and if you meet the conditions (such as the production of abnormal conditions), the client time (30 seconds) Play tone.

I started using ajax to refresh the page, java play sound files. Everything is normal. But running on the server, reported a mistake. After my hard to find, finally found out that the server is not sound, seemingly without a sound card can not play sounds of java.
Later I added directly in the jsp page background sound (bgsound), but there is no sound when the ajax refresh.

Will you master, what solution do?

Sponsored Links

long22259723
2009-04-19 09:58:54
posted the code to see what
Lamwer
2009-04-19 10:10:38

import java.io.File;
import java.io.IOException;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.UnsupportedAudioFileException;

public class Play{
    private String file_path="e:/test.au";
    private AudioInputStream    ais; 
    private SourceDataLine      line; 
    private AudioFormat         baseFormat;
    private static final int    BUFFER_SIZE=4000*4;
    
    private SourceDataLine getLine(AudioFormat audioFormat) {
       SourceDataLine res = null;
       DataLine.Info info = new DataLine.Info(SourceDataLine.class,audioFormat);
       try {
           res = (SourceDataLine) AudioSystem.getLine(info);
           res.open(audioFormat);
       }catch (Exception e) {
           e.printStackTrace();
       }
       return res;
    }
    
    public void play()throws UnsupportedAudioFileException, LineUnavailableException, IOException{
        ais= AudioSystem.getAudioInputStream(new File(file_path));
        baseFormat = ais.getFormat();
        
        line = getLine(baseFormat);
        <span style="color: #FF0000;">line.start();   //jsp </span>
        int inBytes = 0;
        byte[] audioData=new byte[BUFFER_SIZE];    
        while (inBytes != -1){
            inBytes = ais.read(audioData, 0, BUFFER_SIZE);
            if (inBytes >= 0) {
               int outBytes = line.write(audioData, 0, inBytes);
            }
        }
    }
    public static void main(String args[])throws UnsupportedAudioFileException, LineUnavailableException, IOException
    {
    Play p1=new Play();
    p1.play();
    }

}

I disable the network card error after: No line matching ; interface SourceDataLine supporting format PCM_SIGNED 32000.0 Hz, 16 bit, stereo, 4 bytes / frame, big-endian is supported.
enabled NIC After all normal
gjklovelb
2009-04-19 10:18:36
Your logic is not a problem? Why should the server play?

If an exception, the exception should be displayed on the page, the page file calls the associated sound file to play it, ...........

Why should ajax refresh when the sound? Should be refreshed, unusual, page Play sounds right,
modeman
2009-04-19 10:32:00
jsp page abnormalities:

org.apache.jasper.JasperException: An exception occurred processing JSP page /test3.jsp at line 52

49: 
50: <%Play p = new Play();
51: try {
52:  p.play();
53: } catch (UnsupportedAudioFileException e) {
54:  // TODO Auto-generated catch block
55:  e.printStackTrace();


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause 

java.lang.NullPointerException
com.andon.Test.Play.play(Play.java:38)
org.apache.jsp.test3_jsp._jspService(test3_jsp.java:106)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

upstairs comrades can said specific point? How to call on the page and play sound files. If you want to say with the background sound. I have tried this, add background sound jsp file plays correctly, but not static refresh. Jsp file using ajax call after this, the background sound is not played. If you do not mean that, then please let me know.
amdismycpu
2009-04-19 10:46:17
My approach is to use the applet
Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.