PlayListModel Serialization

Most MP3 players load/save their playlists from/to a file with an M3U extension. There is simple M3U and extended M3U (EXTM3U). Simple M3U is just a list of filenames separated by newlines. Extended M3U contains extra information following a # sign on the preceding line. If you use this format, your program will immediately work with the most popular MP3 players.

Serialization, as we discussed in Section 10.6, is the process of taking an object and expressing its state information in a format that allows it to be sent across a network or saved to a storage device such as a file or a database. Deserialization is the process of reconstructing the object from the serialized state information to its original state.

Now that we have a simple data object, we want to be able to serialize and deserialize it. Write two classes, PlayListReader and PlayListWriter for reading/ writing playlist data.

Figure 25.5. Serialization classes for PlayListModel

Категории