im trying to get a playlist jukebox style.... into my program... so far this works as in playing the music, but everytime the play button is selected i want it to go to an arraylist and for 'current' to play everything in the arraylist...
i just need help putting the code together...
so i'd create an array list
say:
arraylist list = new arraylist [9]
then add the selected index to it
{for<int i = 0;i<arrayList, i++>
list[i] = musicList[playList.getSelectedIndex()];
}
and then the current would play whatever was in 'list[s]
s++
see, im not sure how it would go...can you do this with audioclip? this is just to give you a rough idea what im trying to do.... any help in coding this would be much appreciated!
import java.applet.AudioClip;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.MalformedURLException;
import java.net.URL;
import java.io.File;
public class JukeBox extends JFrame {
private JLabel label;
private JPanel panel, buttonPanel;
private JComboBox playList;
private JButton play, stop;
private URL url1, url2, url3, url4, url5, url6;
private AudioClip[] musicList;
private AudioClip current ;
public JukeBox() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500, 120);
setLocation(50, 50);
setTitle("JAVA JukeBox");
url1 = url2 = url3 = url4 = url5 = url6 = null;
current = null;
try {
url1 = new URL("file", "localhost", "C:\\music\\sound.wav");
url2 = new URL("file", "localhost", "C:\\music\\sound.wav");
} catch (MalformedURLException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
musicList = new AudioClip[7];
musicList[0] = null;
musicList[1] = JApplet.newAudioClip(url1);
musicList[2] = JApplet.newAudioClip(url2);
musicList[3] = JApplet.newAudioClip(url3);
musicList[4] = JApplet.newAudioClip(url4);
musicList[5] = JApplet.newAudioClip(url5);
musicList[6] = JApplet.newAudioClip(url6);
label = new JLabel("JAVA JukeBox", JLabel.CENTER);
String[] musicList = {"select a track..."
, "bottle open"
, "bitch please II"
, "flutte, harmonica, mambo"
, "jungle"
, "spacemusic"
, "trippygaia"};
playList = new JComboBox(musicList);
playList.addActionListener(new ListListener());
play = new JButton("Play");
play.setActionCommand("play");
play.addActionListener(new ButtonListener());
stop = new JButton("Stop");
stop.addActionListener(new ButtonListener());
buttonPanel = new JPanel();
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
buttonPanel.add(play);
buttonPanel.add(stop);
panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.add(label);
panel.add(Box.createRigidArea(new Dimension(0, 5)));
panel.add(playList);
panel.add(Box.createRigidArea(new Dimension(0, 5)));
panel.add(buttonPanel);
getContentPane().add(panel);
}
private class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if(current != null){
current.stop();
}
if(e.getActionCommand().equalsIgnoreCase("play")){
if(current != null){
current.play();
}
}
}
}
private class ListListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (current != null) {
current.stop();
}
current = musicList[playList.getSelectedIndex()];
}
}
public static void main(String[] args) {
setDefaultLookAndFeelDecorated(true);
JukeBox jb = new JukeBox();
jb.setVisible(true);
jb.setResizable(false);
}
}