************在JAVA中发个声音好难啊,各位帮帮忙

肖尧19 2001-10-26 04:06:21
代码如下,有什么错误
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.net.*;
public class playsound extends java.applet.Applet
{
public void init()
{
Button btn=new Button("play sound");
btn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try{
AudioClip ac=getAudioClip(getCodeBase(),"mes.au");
ac.play();}
catch(Exception ee)
{
System.out.println("error to play");
System.out.println(ee.getMessage());
}
}
});
add(btn);
}
}
...全文
112 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
肖尧19 2001-10-31
  • 打赏
  • 举报
回复
原来au文件也分几种,我用自己做的au就发不了声,用JDK自带的au文件就搞定了
skyyoung 2001-10-29
  • 打赏
  • 举报
回复
到这里看看吧,解决了不要忘记告诉我一声。
http://www.jsresources.org/examples/
hailong326 2001-10-29
  • 打赏
  • 举报
回复
gz
skyyoung 2001-10-29
  • 打赏
  • 举报
回复
wav文件好象真的不行哦,但MID可以。
shaoyu 2001-10-27
  • 打赏
  • 举报
回复
you are,,,
肖尧19 2001-10-26
  • 打赏
  • 举报
回复
push
肖尧19 2001-10-26
  • 打赏
  • 举报
回复
在你的机器上可以了吗,谢谢,我重新写了一个,按你的方法,还是不行
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
import java.net.*;
import java.io.*;
public class soundtest
{
public static void main(String[] args)
{
JFrame frame=new JFrame();
Container con=frame.getContentPane();
con.setLayout(new FlowLayout());
JButton btn=new JButton("Play Sound");
btn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
File file=new File("d:\\myjavafile\\msg.wav");
AudioClip ac=Applet.newAudioClip(file.toURL());
ac.play();
}
catch(Exception ee)
{
System.out.println(ee.getMessage());
}
}
});
con.add(btn);
frame.setBounds(200,200,200,200);
frame.show();
}
}
skyyoung 2001-10-26
  • 打赏
  • 举报
回复
可以的。试一下就知道啦。
clane 2001-10-26
  • 打赏
  • 举报
回复
.au文件 audioclip支持的吗??不过如果用jmf,mp3的都可以播放。呵呵
skyyoung 2001-10-26
  • 打赏
  • 举报
回复
is it ok?
skyyoung 2001-10-26
  • 打赏
  • 举报
回复
ile file = new File("bark.wav");
AudioClip clip = Applet.newAudioClip(file.toURL());
clip.play();
skyyoung 2001-10-26
  • 打赏
  • 举报
回复
String[] mid = {
"http://localhost/G01.mid",
"http://localhost/G04.mid",
"http://localhost/G12.mid",
"http://localhost/G13.mid",
};
AudioClip audioClip = Applet.newAudioClip(new URL(mid[3]));
audioClip.play();

62,628

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧