well, ive come across another problem. I was getting tired of all these stupid media players that are out right now... WMP has glitches, and will add your music twice to the library, and the way i wanna play my music is it loads the entire library into memory(the String of the path names, of course!), and then play it in ascending artist and album track number(basically, chronological order)... and if wanna listen to another song, then i can just click on it... unlike media players like jaangle, which its completely playlists. so, since im quite a skilled programmer, i decided to make my own based off of JLayer. which turned out great for me, because i dont know how to write one from scratch... but thats still not perfect, and i wrote a very simple gui, and right now(the problem), ive been writing a pause feature... cause thats not built into JLayer. well, guess what... it doesnt work. itll play music..(one...song...at...a...time...)but the pause feature doesnt. so, ima post the code below... hopefully you can help me(its the full program, btw)
import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.ArrayList; import javazoom.jl.player.*; import javax.swing.filechooser.*; import javax.swing.text.*; public class MusicPlayer implements ActionListener { JFrame frame; JPanel panel; Dimension dim; JTextArea main; ArrayList music; int pause; mp player; public MusicPlayer() { frame = new JFrame(); panel = new JPanel(); panel.setLayout(null); frame.getContentPane().add(panel); dim = Toolkit.getDefaultToolkit().getScreenSize(); frame.setBounds(dim.width/2-250,dim.height/2-250,500,500); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); music = new ArrayList(); initGui(); frame.setVisible(true); } public void initGui() { main = new JTextArea(); main.setEditable(false); DefaultCaret caret = (DefaultCaret)main.getCaret(); caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); JScrollPane jsp = new JScrollPane(main); jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); jsp.setBounds(0,0,250,250); panel.add(jsp); Box buttons = new Box(BoxLayout.Y_AXIS); JButton play = new JButton("Play"); play.addActionListener(this); buttons.add(play); JButton pause = new JButton("Pause"); pause.addActionListener(this); buttons.add(pause); JButton load = new JButton("Load"); load.addActionListener(this); buttons.add(load); buttons.setBounds(250,0,250,250); panel.add(buttons); } public static void main(String args[]) { new MusicPlayer(); } public void actionPerformed(ActionEvent e) { String a = e.getActionCommand(); if(a=="Load") { JFileChooser jfc = new JFileChooser(); jfc.setMultiSelectionEnabled(true); jfc.setFileFilter(new FileNameExtensionFilter("MP3","mp3")); jfc.showOpenDialog(frame); File file = jfc.getSelectedFile(); music.add(file.getPath()); main.append(file.getName()); panel.repaint(); } else if(a=="Play") { if(pause==0) { String dir = (String)music.get(0); player = new mp(dir); } else { player = new mp(pause); } } else if(a=="Pause") { player.close(); pause = player.getPos(); } } } class mp implements Runnable { Player ap; Thread thread; boolean isRun; String song; int u = Integer.MAX_VALUE; int a = 0; public mp(String song) { isRun = true; this.song = song; thread = new Thread(this); thread.start(); } public mp(int i) { isRun = true; this.song = song; u = i; thread = new Thread(this); thread.start(); } public void run() { while(isRun==true) { try { FileInputStream fis = new FileInputStream(song); ap = new Player(fis); ap.play(u); } catch(Exception ex) { } } } public int getPos() { return a; } public void close() { a = Integer.MAX_VALUE-ap.getPosition(); ap.close(); isRun = false; thread = null; } }