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 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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -