java简单播放器源码.doc_第1页
java简单播放器源码.doc_第2页
java简单播放器源码.doc_第3页
java简单播放器源码.doc_第4页
java简单播放器源码.doc_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

import java.awt.BorderLayout;import javax.media.Manager;import javax.media.NoPlayerException;import javax.media.Player;import javax.sound.sampled.AudioFormat;import javax.sound.sampled.AudioSystem;import javax.sound.sampled.DataLine;import javax.sound.sampled.SourceDataLine;import javax.swing.ImageIcon;import javax.swing.JFileChooser;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JFrame;import javax.swing.JScrollPane;import java.awt.Rectangle;import javax.swing.JTable;import java.awt.Dimension;import javax.swing.JTextPane;import javax.swing.JScrollBar;import java.awt.List;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.File;import java.io.IOException;import .MalformedURLException;import javax.swing.JButton;import javax.swing.filechooser.FileNameExtensionFilter;public class Hello extends JFrame implements ActionListener private static final long serialVersionUID = 1L;private JPanel jContentPane = null;private List list = null;private JButton jButton = null;private Player play; / jve:decl-index=0:private String str = null;private JButton jButton1 = null;private JButton jButton2 = null;private boolean b=false;private static SourceDataLine objSDL;private JButton jButton3 = null;/* * This is the default constructor */public Hello() super();ImageIcon backIcon = new ImageIcon(getClass().getResource(/image/hehe.jpg);final JLabel backLabel = new JLabel(backIcon); / 创建背景标签backLabel.setSize(backIcon.getIconWidth(), backIcon.getIconHeight();backLabel.setLocation(0, 0);this.add(backLabel);initialize();/* * This method initializes this * * return void */private void initialize() this.setSize(594, 346);this.setContentPane(getJContentPane();this.setTitle(达达播放器);setVisible(true);/* * This method initializes jContentPane * * return javax.swing.JPanel */ Start Output/* 打开音频设备.* param intFreq 采样率。* param iBits PCM位深(例如16)。* param channels 声道数*/private JPanel getJContentPane() if (jContentPane = null) jContentPane = new JPanel();jContentPane.setLayout(null);jContentPane.add(getList(), null);jContentPane.add(getJButton(), null);jContentPane.add(getJButton1(), null);jContentPane.add(getJButton2(), null);jContentPane.add(getJButton3(), null);return jContentPane;public void play(String str, List list) File ff = new File(str + list.getSelectedItem();try play = Manager.createPlayer(ff.toURL(); catch (NoPlayerException e1) / TODO Auto-generated catch blocke1.printStackTrace(); catch (MalformedURLException e1) / TODO Auto-generated catch blocke1.printStackTrace(); catch (IOException e1) / TODO Auto-generated catch blocke1.printStackTrace();play.start();/* * This method initializes list * * return java.awt.List */private List getList() if (list = null) list = new List();list.setBounds(new Rectangle(67, 16, 425, 206);list.addItemListener(new java.awt.event.ItemListener() public void itemStateChanged(java.awt.event.ItemEvent e) if (play = null) play(str, list);b=true; else play.close();play(str, list););return list;/* * This method initializes jButton * * return javax.swing.JButton */private JButton getJButton() if (jButton = null) jButton = new JButton();jButton.setBounds(new Rectangle(15, 244, 128, 31);jButton.setText(添加歌曲文件夹);jButton.addActionListener(this);return jButton;public void actionPerformed(ActionEvent e) JFileChooser jchoose = new JFileChooser();jchoose.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);FileNameExtensionFilter filter = new FileNameExtensionFilter(MP3,MP3);jchoose.setMultiSelectionEnabled(true);/ 选择文件夹jchoose.setFileFilter(filter);jchoose.setMultiSelectionEnabled(true);jchoose.showOpenDialog(this);if (jchoose.getSelectedFile() != null) if (list != null)list.clear();File file = jchoose.getSelectedFile();str = jchoose.getCurrentDirectory()+ jchoose.getSelectedFile().getName() + ;File f = file.listFiles();for (int i = 0; i f.length; i+) if (fi.getName().endsWith(.mp3)list.add(fi.getName();/* * This method initializes jButton1 * * return javax.swing.JButton */private JButton getJButton1() if (jButton1 = null) jButton1 = new JButton();jButton1.setBounds(new Rectangle(155, 246, 115, 30);jButton1.setText(随机播放);jButton1.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent e) / Thread Haha=new RadamPlay(list);/ Haha.start(););return jButton1;/* * This method initializes jButton2 * * return javax.swing.JButton */private JButton getJButton2() if (jButton2 = null) jButton2 = new JButton();jButton2.setBounds(new Rectangle(280, 246, 81, 30);jButton2.setText(暂停);jButton2.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent e) if(play!=null) play.stop(); );return jButton2;/* * This method initializes jButton3 * * return javax.swing.JButton */private JButton getJButton3() if (jButton3 = null) jButton3 = new JButton();jButton3.setBounds(new Rectangle(380, 247, 89, 29);jButton3.setText(播放);jButton3.addActio

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论