Hi, i`ve made a simpel media player that can open and play mp3 tracks.
And now i wanna try to make it open/create and save playlist.
any hints on how to start??

Apreciate your time! =)

the code for the player is here http://www.daniweb.com/forums/thread177216.html

that depends
is it supposed to work only for your player, does it have to be compatibel with (for instance) winamp, ... ?

if it just has to be for your own player, you can always create a file and fill that with (for instance)


read that in, load the contents in a Collection and when you get to the track you want, load it as a File-Object to play.

I wasn't allowed to use the standard formats for my application when I wrote it, so haven't really checked out how that worked

OK, now ive made an additional window with a JTextArea on it.
Ive also made a JButton that adds a selected files absolute filepath to the textfield.
Now i need a function that can "withdraw" the selected (marked) filepath from the textfield. My plan is to have a play button that is coded the same way as the original open file function, only differense will be that it plays the filepath withdrawed from the textfield.

Like this

            player.addControllerListener(new EventHandler());

Where selectedsong() is the method that i want to return the filepath.

Is this possible? and if so, whith what function.
Appreciate all help!

ive found the correct mode and made it work.
Now my problem is when i save/open the playlist.
Save mode looks like this:
as is the model for the list.
and liste in the actual JList.
File f;

public void savePlayList(){

    JFileChooser fileChooser=new JFileChooser();
    int result=fileChooser.showSaveDialog(this);
    if (result==JFileChooser.CANCEL_OPTION)
    File f=fileChooser.getSelectedFile();
        if (f.exists()) return;
        FileOutputStream fw=new FileOutputStream(f);
        ObjectOutputStream obj=new ObjectOutputStream(fw);

    catch (Exception e){


This works as it save a file on my computer in my choosen path and filename.

Problem occurs when i try to open the plalist again.
Open mode looks like this:

public void openPlayList(){

    JFileChooser chooser=new JFileChooser();
    int res=chooser.showOpenDialog(this);
    File f=chooser.getSelectedFile();
        FileInputStream filein=new FileInputStream(f);
        ObjectInputStream objin=new ObjectInputStream(filein);
        Object o=objin.readObject();
    catch (Exception e){

1. the button linked to this mode only activates when i have a playlist open
2.when i have it open and use the openPlayList function
i get this errormessage;
writing aborted; java.io.NotSerializableException: Archive

where Archive is a seperate class for the list model.
so as(the model is set like this )
Archive as new Archive();

and now the seperate class

public class Archive {

    public DefaultListModel listModel;
    private ArrayList<Song> al;

    public Archive(){
        al=new ArrayList<Song>();
        listModel =new DefaultListModel();

public DefaultListModel getListModel() {
        return listModel;

What am i doing wrong?? =P

If you want to read/write an object via writeObject / readObject the object's class must implement the Serializable interface. It's a bit weird, because that interface doesn't define any methods! It's a sort of flag to Java that if you define the class (Archive) as implements Serialiable then you expect instances of that class to be able to be written/read from object streams. If your class's instance variables are only simple things like Strings you don't have to do anything else, but if they are more complicated you MAY have to define methods to convert them to a form that can be read/written to a stream. If you're not sure, just add the implements Serialiable and see if that works first.

That worked along with some small modifications.
changed my openPlayList mode to


Thx alot =)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.