代码如下:
import java.applet.Applet;
import java.applet.AudioClip;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Scanner;
class test extends Exception{
String message;
test(){message="不支持的文件格式";}
}
class audioplay{
AudioClip adc;// 声音音频剪辑对象
URL url; //wav文件路径
void SetPlayAudioPath(String path) throws test {//选择播放文件
if(!path.endsWith(".wav")){
throw new test();
}
try{
url = new URL("file:"+".\"+path);
adc = Applet.newAudioClip(url);
}
catch (MalformedURLException e1) {
e1.printStackTrace();
}
}
void play(){ //播放wav文件
adc.play();
System.out.println("播放中");
}
void stop(){ //停止播放wav文件
adc.stop();
System.out.println("已经停止");
}
}
public class filemusic{
public static void main(String[] args) {
audioplay audioPlay=new audioplay();
Scanner reader=new Scanner(System.in);
String str=new String();
String st=new String();
do{
System.out.println("请输入文件名: ");
str=reader.nextLine();
}while(!str.endsWith(".wav"));
do{
System.out.println("/*********************/");
System.out.println("播放:play");
System.out.println("停止:stop");
System.out.println("退出:exit");
System.out.println("/*********************/");
st=reader.nextLine();
if(st.equals("play")){
try{
audioPlay.SetPlayAudioPath(str);
}
catch(test e)
{System.out.println(e.message);
}
audioPlay.play();
}
if(st.equals("stop")){
audioPlay.stop();
}
}while(!st.equals("exit"));
}
}
eclipse上wav播放的java代码正常运行,但是没法放出声音,硬件正常,求解答,谢谢谢谢!!!
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
悬赏问题
- ¥15 如何在scanpy上做差异基因和通路富集?
- ¥20 关于#硬件工程#的问题,请各位专家解答!
- ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
- ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
- ¥30 截图中的mathematics程序转换成matlab
- ¥15 动力学代码报错,维度不匹配
- ¥15 Power query添加列问题
- ¥50 Kubernetes&Fission&Eleasticsearch
- ¥15 報錯:Person is not mapped,如何解決?
- ¥15 c++头文件不能识别CDialog