0

我使用 JLayer 播放 mp3 文件。

我有一系列文件,我可以播放歌曲,转到下一首,但我不知道如何在第一次停止时转到下一首歌曲。

我有五种方法

当歌曲停止时,我得到playbackEnded但我无法处理下一首歌。

这是我的代码

public class SoundJLayer extends PlaybackListener implements Runnable{
    private String filePath;
    private AdvancedPlayer player;
    private Thread playerThread;  

    public SoundJLayer(File file){
    this.filePath = file.getPath();
    }
    public void play(){
    try{
         String urlAsString = 
                 "file:///" 
                 + this.filePath;

        this.player = new AdvancedPlayer
        (
            new java.net.URL(urlAsString).openStream(),
            javazoom.jl.player.FactoryRegistry.systemRegistry().createAudioDevice()
        );

        this.player.setPlayBackListener(this);

        this.playerThread = new Thread(this, "AudioPlayerThread");

        this.playerThread.start();
    }
    catch (Exception ex)
    {
        ex.printStackTrace();
    }
    }
    public void playbackStarted(PlaybackEvent playbackEvent){
    System.out.println("playbackStarted()");
    }
    public void playbackFinished(PlaybackEvent playbackEvent){
    System.out.println("playbackEnded()");
    } 
}

public class MyFrame extends JFrame implements ActionListener,ChangeListener{

    void playNext(){
    soundToPlay.stop();

       soundToPlay = new SoundJLayer(playlist[currentIndex]);
       soundToPlay.play();
    }

我想在playNext()什么时候调用playbackFinishedMyFrame().playNext()不起作用

4

0 回答 0