我想创建一个播放shoutcast流的程序。 我从here复制此代码,我发现以下错误消息。 我使用BasicPlayer库,如果您有任何其他库建议,它对我非常有帮助!
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javazoom.jlgui.basicplayer.BasicController;
import javazoom.jlgui.basicplayer.BasicPlayer;
import javazoom.jlgui.basicplayer.BasicPlayerEvent;
import javazoom.jlgui.basicplayer.BasicPlayerException;
import javazoom.jlgui.basicplayer.BasicPlayerListener;
public class MP3Player implements BasicPlayerListener, Runnable {
public String streamurl;
public BasicController playerControl;
private BasicPlayer player;
private volatile boolean shouldPlay = true;
@Override
public void run() {
while (true) {
if (shouldPlay) {
player();
}
}
}
public void start() {
new Thread(this).start();
}
public void pause() {
shouldPlay = false;
try {
playerControl.stop();
} catch (BasicPlayerException ex) {
Logger.getLogger(MP3Player.class.getName()).log(Level.SEVERE, null,
ex);
}
}
public void play() {
shouldPlay = true;
}
public MP3Player(String givenStreamurl) {
streamurl = givenStreamurl;
}
public void player() {
shouldPlay = false;
player = new BasicPlayer();
playerControl = (BasicController) player;
player.addBasicPlayerListener(this);
try {
try {
playerControl.open(new URL(streamurl));
} catch (MalformedURLException ex) {
System.out.println("aaa");
}
playerControl.play();
playerControl.setGain(0.85);
playerControl.setPan(0.0);
} catch (BasicPlayerException ex) {
}
}
}
错误消息
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at javazoom.jlgui.basicplayer.BasicPlayer.<clinit>(Unknown Source)
at MP3Player.player(MP3Player.java:57)
at Main.main(Main.java:6)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 3 more
第57行
player = new BasicPlayer();
感谢名单!
答案 0 :(得分:1)
由于例外显然是classnotfoundexception
,这意味着它无法在类路径中找到类org.apache.commons.logging.LogFactory
。
从commons-logging下载jar并将其放入类路径中。