Sending audio dircetly to the speakers java -


the title tells story, send audio directly speaker system java program, thinking of trying write directly speakers in /dev/ in linux using bytes obtained audio file, i'm not sure work, in windows i'm beyond stumped. thinking along lines of this:

public void play(byte[] audio){    if(os.iswindows){//this have no idea, maybe write javasound jmf? } if(os.islinux){     bufferedoutputstream bout = new bufferedoutputstream(new fileoutputstream("/dev/blahblah");     bout.write(audio)     bout.flush();     bout.close();  } 

my code seems simple me, not want complicated code, want working code. havent tried above code, in fear dont know im doing, , possibly hurt or interrupt in pc.

you can't cat tune.wav > /dev/dsp anymore (not without some tricks), , way attempting sounds low level - choose library.

you might have luck standard ones such javax.sound (simple) , jmf (more features).

or try third party library such jogamp joal (feature rich), can use windows , linux (through native libraries).

edit: mp3

  1. just noticed java 7's javafx can easily, see this answer

  2. to roll own javax.sound: follow tutorial on creating spi* create audiofilereader handling mp3s. (note previous spi link javax.sound specific, spi general concept)

  3. alternatively jmf can handle mp3s with this, , can lookup how nest jars etc if you're determined provide single artifact.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -