java 中wav文件格式_请教java中,wav文件的播放问题

代码如下,是书上看来的,但是不知道为什么怎么也播放不出来,希望能有人解答~还有,播放的三个音频文件是放在.java的同一个文件夹中吗?classMypYextendsPanelimplementsRunnable,It...

代码如下,是书上看来的,但是不知道为什么怎么也播放不出来,希望能有人解答~还有,播放的三个音频文件是放在.java的同一个文件夹中吗?

class MypY extends Panel implements Runnable,ItemListener,ActionListener{

Thread thread;

Choice choice;

AudioClip clip;

URL url;

JavaSoundAudioClip player;

Button buttonPlay;//播放按钮

Button buttonLoop;//循环按钮

Button buttonStop;//停止按钮

String str;

MypY(){

thread=new Thread(this);

choice=new Choice();

choice.add("Firstsong.wav");

choice.add("Secondsong.wav");

choice.add("Thirdsong.wav");

choice.addItemListener(this);

buttonPlay=new Button("播放");

buttonLoop=new Button("循环");

buttonStop=new Button("停止");

buttonPlay.addActionListener(this);

buttonLoop.addActionListener(this);

buttonStop.addActionListener(this);

add(choice);

add(buttonPlay);

add(buttonLoop);

add(buttonStop);

str="Firstsong.wav";

}

public void run() {

try{

File file=new File(str);

url=file.toURL();

clip = Applet.newAudioClip(url);

}

catch(Exception e4)

{

System.out.println(e4);

}

}

public void itemStateChanged(ItemEvent arg0) {

str=choice.getSelectedItem();

if(!(thread.isAlive()))

{

thread=new Thread(this);

}

try{

thread.start();

}

catch(Exception ee){}

}

public void actionPerformed(ActionEvent e5) {

if(e5.getSource()==buttonPlay)

{

clip.play();

}

if(e5.getSource()==buttonLoop)

{

clip.loop();

}

if(e5.getSource()==buttonStop)

{

clip.stop();

}

}

}

这只是我建的一个类,main函数在别的类中,但是其他运行一切正常,我放在主要的那个frame中,只有这个播放不了,好像是clip的值是null,好像有说值没传进去的,希望可以得到进一步的解答~

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值