java制作音乐播放列表_教你轻松制作java音乐播放器

一、音乐播放器的实现原理

Javase的多媒体功能很弱,所以有一个专门处理多媒体的插件叫JMF,JMF提供的模型可大致分为七类

* 数据源(Data source)

* 截取设备(Capture Device,包括视频和音频截取设备)

* 播放器(Player)

* 处理器(Processor)

* 数据池(DataSink)

* 数据格式(Format)

* 管理器(Manager)

而我所做的这个音乐播放器MyMusicPlayer(这是我创建的类名)正是调用了JMF中的Player类来实现其播放等各种功能.

我们首先要做的就是要安装JMF。JMF的安装,相信对于许多的新手来说是很伤脑筋的,JMF只支持32位的JDK版本,然而像eclipse这样的IDE环境要与JDK对应,也就是IDE环境要支持32位JDK版本。当安装完JMF之后,有时候对于MP3的播放并不成功,还需要装JMF的mp3plugin。

二、界面效果图

9deb0270b6cdd3ad9a6d1f7d30c0ee24.png

三、功能结构图

6bf3876214e59b5abc3b0a53dbad5d2b.png

四、各种实现功能的代码

public class MyMusicPlayer implements ActionListener, ControllerListener,Runnable{

JFrame j=new JFrame("音乐播放器");

JLabel TablePlaer=new JLabel("播放列表");

JButton BAdd=new JButton("添加歌曲");

JButton BDelect=new JButton("删除歌曲");

JButton BDelectTable=new JButton("清空列表");

JButton BMoveNext=new JButton("下一曲");

JButton BMovePrevious=new JButton("上一曲");

JButton BPlayer=new JButton("暂停");

JButton BStop=new JButton("停止");

JButton BSet=new JButton("显示歌词");

JButton BEnd=new JButton("停止");

String[] s={"顺序播放","单曲循环","随机播放"}; //下拉列表选项数组

JComboBox select=new JComboBox(s); //创建下拉选项

JPanel p1=new JPanel(); //播放列表区域

JPanel p=new JPanel();

JPanel p2=new JPanel(); //按钮区域

JPanel p3=new JPanel();

JLabel l=new JLabel();

JPanel p5=new JPanel(); //放置播放列表

JPanel p6=new JPanel(); //放置播放歌曲的名称

static JPanel pp=new JPanel();

static JLabel lb;

public static JTextArea jt=new JTextArea();

static int index; //播放列表的下标

int count;

int flag; //标记是随机播放还是顺序播放

int countSecond; //获取音乐的总时间值

static int newtime = 0;

int ischanging = 0; //当鼠标是对游标进行点击,进度值也会改变

int ispressing = 0; //判断鼠标是否对游标进行点击

File MusicName = null;

static java.util.List MusicNames = null; //运用泛型,创建File对象

File currentDirectory = null;

List list;// 文件列表

FileDialog open; // 定义文件对话框对象

Random rand = new Random();

String filename;

//进度条

JButton timeInformation = new JButton();

JSlider timeSlider = new JSlider(SwingConstants.HORIZONTAL, 0, 100, 0); //(SwingConstants.HORIZONTAL)用于定向进度条为水平方向的常量的集合

//( 0, 100, 0)用指定的最小值、最大值和初始值创建一个水平滑块。

// 播放

Player player = null;

MusicFileChooser fileChooser = new MusicFileChooser();

static JTextPane tp=new JTextPane(); //显示歌词区域

static JTextArea are=new JTextArea(); //显示图片区域

public MyMusicPlayer(){

j.setSize(1200, 700);

j.setLayout(null);

j.getContentPane().setBackground(Color.BLACK);

j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

p.setBounds(2, 563, 1180, 95);

p.setLayout(new BorderLayout());

p1.setBounds(2, 3, 298, 30);

p1.setBackground(new Color(255,255,255));

p2.setLayout(new GridLayout(2,3,20,20));

p2.setBackground(Color.LIGHT_GRAY);

p3.setLayout(new GridLayout(2,0,200,10));

p3.setBackground(new Color(255,255,255));

p5.setBounds(2, 35, 298, 526);

p5.setLayout(null);

p5.setBackground(new Color(255,255,255));

p6.setBounds(30

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值