java shooutcast:我有错误与基本播放器



我想创建一个播放广播流的程序。我从这里复制这段代码,我有下面的错误信息。我使用的是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();

谢谢!

异常明确地表示classnotfoundexception,这意味着它无法在类路径中找到org.apache.commons.logging.LogFactory类。

从common_logging下载jar文件,并把它放到你的类路径中。

相关内容

  • 没有找到相关文章

最新更新