soulTrouble 2017-10-14 06:37 采纳率: 0%
浏览 2040

eclipse上wav播放的java代码正常运行,但是没法放出声音,硬件正常,求解答,谢谢谢谢!!!

代码如下:
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"));
}
}

  • 写回答

1条回答

  • devmiao 2017-10-14 15:50
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。