我想通过命令行使用 java 播放声音文件。
到目前为止,我已成功列出目录的内容,但无法播放 wav 文件
列出目录内容的代码
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 with error code "+exitVal);
播放wav文件的代码,这不起作用
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 with error code "+exitVal);
我收到以下错误
Exited with error code 1