Java写的音乐播放器代码运行出错javax.media.NoPlayerException: Cannot find a Player for :F:\Mus
下面是代码,运行后点击列表的歌曲,出现javax.media.NoPlayerException: Cannot find a Player for :F:\Music\05 浮光.mp3
import javax.media.*;
import javax.swing.*;
import java.util.Vector;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.event.ListSelectionEvent;
public class JavaMusicPlayer extends JFrame implements ActionListener,
ItemListener, ControllerListener{
private String title; //标题
private Player player; //播放器
//控制播放的布尔变量
private boolean first = true,loop = false;
private String[] songs = {"未添加过歌曲"};
private Vector vt = new Vector(); //使用向量存储添加的歌曲
private JList songList; //列表框显示歌曲列表
private Component vc, cc;
private String currentDirectory=null; //当前目录初始化为空
private String cufile; //当前文件路径
private String selectFile; //选择的文件名
/** 构造方法 */
JavaMusicPlayer(String title) {
super(title);
// 初始化歌曲列表,并设置相关属性
songList = new JList(songs);
add(songList,BorderLayout.CENTER);
// 关闭按钮的实现
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
}
//窗口关闭函数
public void windowClosed(WindowEvent e) {
//注意关闭播放器
if (player != null)
player.close();
System.exit(0);
}
});
// 调用程序菜单栏的方法成员完成菜单的布置
setupMenu();
setSize(400, 400);
setVisible(true);
//实现点击歌曲列表就播放点击的歌曲
songList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e){
String path = songList.getSelectedValue().toString();
if (player != null) {
player.close();
}
// 创建播放器时需要捕捉一些异常
try {
Player musicplayer = Manager.createPlayer(new MediaLocator(path));
//问题在此,画了红曲线,换成removeControllerListener也不行