我想创建一个程序来播放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行是
玩家=新的BasicPlayer();
谢谢!
最佳答案
异常清楚地表明classnotfoundexception
,这意味着它无法在类路径中找到类org.apache.commons.logging.LogFactory
。
从commons-logging下载jar并将其放在您的类路径中。