简体   繁体   中英

Sound output buffer flush

I have a jsp that plays wav file through java class in GlassFish. I have used SourceDataline methods:

start();
drain();
close();

The wav file is played properly. For stopping I used:

stop();
flush();
close();

But the play continues with the rest of data inside the output buffer. I went through the documents over www.oracle.com about SourceDataline methods. There it is said that flush() will discard the data inside the SourceDataline object but not the data already inside the output buffer.

Now I want to flush out the data from the output buffer so that there will be no overlapping of sound during the next start. I searched on JavaScript also but without help.

This is mostly a shot in the dark, but could work: the documentation for TargetDataLine.read says:

Reads audio data from the data line's input buffer. (...) However, if the data line is closed, stopped, drained, or flushed before the requested amount has been read, the method no longer blocks, but returns the number of bytes read thus far.

So, maybe you can try to gain access to the TargetDataLine(s) being used (maybe using Mixer.getTargetLines ) and try to act on them too (stopping, flushing etc). I'm not sure, however, if there would be any side-effects of doing that (or even if it's possible at all).

Is there any additional info about your problem you can share? You mentioned jsp, GlassFish and JavaScript, so I'm guessing you're either using an Applet to play the file, or maybe just using Java to mix server-side but sending the resulting file to be handled by the browser. Is any of this correct?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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