【使用AudioClip编的一个播放音乐的小程序,无法正常播放音乐,是哪里的问题啊?】

青柠CC 2015-08-24 01:00:14
import java.applet.*; import java.awt.*; import java.awt.event.*; import java.io.File; import java.net.MalformedURLException; import java.net.URL; import javax.swing.*; public class t1 extends JApplet{ private AudioClip ac; private JButton jbtPlay,jbtLoop,jbtStop; public t1() { setLayout(new GridLayout(1,3)); add(jbtPlay=new JButton("Play")); add(jbtLoop=new JButton("Loop")); add(jbtStop=new JButton("Stop")); URL urlAudio=this.getClass().getResource("music/Gee.mid"); ac=Applet.newAudioClip(urlAudio); jbtPlay.addActionListener(new ButtonListener()); jbtLoop.addActionListener(new ButtonListener()); jbtStop.addActionListener(new ButtonListener()); } class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { if(e.getSource()==jbtPlay) ac.play(); else if(e.getSource()==jbtLoop) ac.loop(); else if(e.getSource()==jbtStop) ac.stop(); } } public static void main(String[] args) throws MalformedURLException { JFrame frame = new JFrame(); t1 applate=new t1(); frame.add(applate); frame.setSize(420,80); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
...全文
1363 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
guanyue.space 2016-04-21
  • 打赏
  • 举报
回复
URL urlAudio=this.getClass().getResource("music/Gee.mid"); 这一段什么意思?AudioClip可以播放.mid格式的音乐吗? 同为菜鸟啊! 我试了一下我常用的方式,可以播放了 代码; package htht; import java.applet.*; import java.awt.*; import java.awt.event.*; import java.io.File; import java.net.MalformedURLException; import java.net.URL; import javax.swing.*; public class tt1 extends JApplet{ private AudioClip ac; private JButton jbtPlay,jbtLoop,jbtStop; @SuppressWarnings("deprecation") public tt1() { setLayout(new GridLayout(1,3)); add(jbtPlay=new JButton("Play")); add(jbtLoop=new JButton("Loop")); add(jbtStop=new JButton("Stop")); //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@唯一改动处 ST File f=new File("C:\\Users\\mao\\Music\\nibawoguanzui.wav"); URL urlAudio; try { urlAudio = f.toURL(); ac=Applet.newAudioClip(urlAudio); } catch (MalformedURLException e1) { // TODO 自动生成的 catch 块 e1.printStackTrace(); } //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@唯一改动处 ED jbtPlay.addActionListener(new ButtonListener()); jbtLoop.addActionListener(new ButtonListener()); jbtStop.addActionListener(new ButtonListener()); } class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { if(e.getSource()==jbtPlay) ac.play(); else if(e.getSource()==jbtLoop) ac.loop(); else if(e.getSource()==jbtStop) ac.stop(); } } public static void main(String[] args) throws MalformedURLException { JFrame frame = new JFrame(); tt1 applate=new tt1(); frame.add(applate); frame.setSize(420,80); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
青柠CC 2016-03-30
  • 打赏
  • 举报
回复
求指教啊!
青柠CC 2016-03-30
  • 打赏
  • 举报
回复
引用 3 楼 qq_27913951的回复:
我看了jdk的源码后发现AudioClip接口中的play(),loop()方法都没有具体的实现内容....所以,,播放不了...
那该怎么办啊?这个问题现在我也不知道怎么解决。。
qq_27913951 2015-10-17
  • 打赏
  • 举报
回复
我看了jdk的源码后发现AudioClip接口中的play(),loop()方法都没有具体的实现内容....所以,,播放不了...
青柠CC 2015-08-25
  • 打赏
  • 举报
回复
求指教
青柠CC 2015-08-24
  • 打赏
  • 举报
回复
没有报错,但是按“Play”按钮并未播放音乐,是哪里的问题啊?求指教~

58,454

社区成员

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

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