command line - Java to play audio file through the commandline -
i play sound file using java through command line.
so far have succeded @ listing contents of directory, cannot play wav file
code list content of directory
process p = runtime.getruntime().exec(new string[]{"/bin/bash","-c","ls"}); bufferedreader input = new bufferedreader(new inputstreamreader(p.getinputstream())); string line=null; while((line=input.readline()) != null) { system.out.println(line); } int exitval = p.waitfor(); system.out.println("exited error code "+exitval);
code play wav file, doesn't work
process p = runtime.getruntime().exec(new string[]{"/usr/bin/aplay","~/javafx/examples/prayertime/dist/police_s.wav"}); bufferedreader input = new bufferedreader(new inputstreamreader(p.getinputstream())); string line=null; while((line=input.readline()) != null) { system.out.println(line); } int exitval = p.waitfor(); system.out.println("exited error code "+exitval);
i following error
exited error code 1
here slight variation of code seen in info. page javasound tag.
import java.net.url; import javax.sound.sampled.*; public class loopsound { public static void main(string[] args) throws exception { url url = new url( "http://pscode.org/media/leftright.wav"); clip clip = audiosystem.getclip(); // getaudioinputstream() accepts file or inputstream audioinputstream ais = audiosystem. getaudioinputstream( url ); clip.open(ais); clip.loop(clip.loop_continuously); thread.sleep(5000); } }
it works command line.
Comments
Post a Comment