java播放暂停按钮_怎么实现按钮的暂停与播放,求大神解答,谢谢

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

import java.awt.EventQueue;

import java.io.*;

import java.util.*;

import javax.swing.JFrame;

import javax.swing.JSlider;

import javax.swing.JButton;

import javax.media.*;

import java.applet.*;

import jmapps.ui.JMFrame;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

import javax.swing.JList;

import javax.swing.JTextArea;

import javax.swing.JSpinner;

import javax.swing.JComboBox;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.lang.*;

import jmapps.jmstudio.CaptureDialog;

import jmapps.ui.PlayerFrame;

import jmapps.util.CDSWrapper;

import jmapps.util.JMFUtils;

public class bofangqi extends Applet implements ControllerListener{

private JFrame frame;

//播放对象

private Player player;

//是否循环播放

private boolean first,loop;

//文件路径

private String path;

//存放MP3文件

private List mp3List;

//当前MP3文件数量

private int mp3NO=0;

public boolean i=true;

bofangqi(List mp3List)

{

this.mp3List=mp3List;

}

/**

* Launch the application.

*/

//播放方法

public void start()

{

try {

player = Manager.createPlayer(new File(mp3List.get(mp3NO)).toURI().toURL());

} catch (NoPlayerException e) {

// TODO 自动生成 catch 块

e.printStackTrace();

System.out.println("不能播放此文件!");

return;

} catch (IOException e) {

// TODO 自动生成 catch 块

e.printStackTrace();

return;

}

if(player==null)

{

System.out.println("播放文件为空!");

return;

}

player.addControllerListener(this);

//提取媒体内容

player.prefetch();

}

public void controllerUpdate(ControllerEvent e) {

//当媒体播放结束时,循环播放

if(e instanceof EndOfMediaEvent)

{

mp3NO++;

System.out.println(mp3NO);

if(mp3NO

{

this.start();

}

return;

}

//当提取媒体的内容结束

if (e instanceof PrefetchCompleteEvent) {

System.out.println("内容结束");

player.start();

return;

}

//当实例化后

if (e instanceof RealizeCompleteEvent) {

System.out.println("实例化");

//pack(); //执行pack()操作

return;

}

}

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {

public void run() {

try {

bofangqi window = new bofangqi();

window.frame.setVisible(true);

} catch (Exception e) {

e.printStackTrace();

}

}

});

List path=new ArrayList();

path.add("C:\\Users\\Administrator.P5LPMC6WDCYRLP5\\Music\\无言无语.mp3");

path.add("C:\\Users\\Administrator.P5LPMC6WDCYRLP5\\Music\\美丽之景.mp3");

path.add("C:\\Users\\Administrator.P5LPMC6WDCYRLP5\\Music\\你的名字我的姓氏.mp3");

bofangqi play=new bofangqi(path);

play.start();

}

/**

* Create the application.

*/

public bofangqi() {

initialize();

}

/**

* Initialize the contents of the frame.

*/

public void initialize() {

frame = new JFrame();

frame.setBounds(100, 100, 382, 361);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane().setLayout(null);

JButton btnNewButton = new JButton("\u524D\u4E00\u9996");

btnNewButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

if(mp3NO<0)

{

mp3NO=mp3List.size()-1;

}

else{

mp3NO--;

}

}

});

btnNewButton.setBounds(27, 64, 93, 23);

frame.getContentPane().add(btnNewButton);

final JButton btnNewButton_1 = new JButton("\u6682\u505C");

btnNewButton_1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

if(i==true) {btnNewButton_1.setText("播放");

i=false;

player.notify();

}

else {btnNewButton_1.setText("暂停");

i=true;}

}

});

btnNewButton_1.setBounds(130, 64, 93, 23);

frame.getContentPane().add(btnNewButton_1);

JButton btnNewButton_2 = new JButton("\u4E0B\u4E00\u9996");

btnNewButton_2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

}

});

btnNewButton_2.setBounds(235, 64, 93, 23);

frame.getContentPane().add(btnNewButton_2);

}

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值