I have a User Interface that handles a playlist, when you double click the song, it plays the song you selected, but after the song ends it starts at the first song in the directory ( I hope this made sense... )
The class that plays MIDI files, loads all the songs from a directory into a queue in the EXACT order as they are in the directory
What I want to do is whenever I play a song in the playlist, I want it to remove all the songs BEFORE it from the queue so that it only plays the songs following it
But I'm clueless to how to do that
This class is where the queue takes place,
package sign; import java.util.Queue; import java.util.LinkedList; import java.io.File; import javax.sound.midi.*; public class PlayMusicInOrder { private static Sequencer seq; private static Queue<String> songQueue; public PlayMusicInOrder (Queue<String> songQueue) { Sequencer seq = null; try { seq = MidiSystem.getSequencer(); seq.addMetaEventListener( new MetaEventListener() { public void meta(MetaMessage msg){ if(msg.getType()==0x2F) { playNextSong(); } } }); } catch (Exception e){} PlayMusicInOrder.seq = seq; PlayMusicInOrder.songQueue = songQueue; } public static void playNextSong(){ String nextSong = songQueue.remove(); System.out.printf("Creating sequence for %s", nextSong); try { Sequence sequence = MidiSystem.getSequence(new File(nextSong)); seq.setSequence(sequence); System.out.println("Playing"); PlayMusicInOrder.seq.start(); } catch (Exception e){ e.printStackTrace(); playNextSong(); } } public void startplaying () { try { seq.open(); } catch (Exception e){ e.printStackTrace(); } playNextSong(); } public static void play(){ Queue<String> songqueue = new LinkedList<String>(); PlayMusicInOrder.addMidiFiles(songqueue,new File( "C:\\Users\\Kyle\\Desktop\\clieent\\Client\\cache\\Music\\")); PlayMusicInOrder player = new PlayMusicInOrder (songqueue); player.startplaying(); }; public static void addMidiFiles(Queue<String> queue, File topdir){ try { for (File f: topdir.listFiles()) if (f.isDirectory()) { addMidiFiles(queue, f); } else if (f.isFile()) { //System.out.println(f); queue.add(f.getAbsolutePath()); } else {} } catch (NullPointerException e) { e.printStackTrace(); } } }
Any help would be appreciated
If I'm missing any information, please let me know.
p.s What is a 'trackback'?
I'm new here