该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
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);
}
}