1 /* 2 * PlaylistFileReader.h - Media Player for the Haiku Operating System 3 * 4 * Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de> 5 * Copyright (C) 2007-2009 Stephan Aßmus <superstippi@gmx.de> (MIT ok) 6 * Copyright (C) 2008-2009 Fredrik Modéen <[FirstName]@[LastName].se> (MIT ok) 7 * 8 * Released under the terms of the MIT license. 9 */ 10 #ifndef __PLAYLIST_FILE_READER_H 11 #define __PLAYLIST_FILE_READER_H 12 13 14 #include <SupportDefs.h> 15 16 class BString; 17 struct entry_ref; 18 class Playlist; 19 20 enum PlaylistFileType {m3u, pls, unknown}; 21 22 23 class PlaylistFileReader { 24 public: 25 virtual ~PlaylistFileReader() {} 26 // Defined to enable deletion of PlaylistFileReader* target objects. 27 28 virtual void AppendToPlaylist(const entry_ref& ref, 29 Playlist* playlist) = 0; 30 static PlaylistFileReader* GenerateReader(const entry_ref& ref); 31 // Returns a pointer to an object of the appropriate derived class, 32 // or returns NULL if the argument is not a valid playlist file. 33 34 protected: 35 int32 _AppendItemToPlaylist(const BString& entry, Playlist* playlist); 36 // Returns the track's playlist index if it was successfully added, else returns -1. 37 // BString& entry is a (absolute or relative) file path or URL 38 39 private: 40 static PlaylistFileType _IdentifyType(const entry_ref& ref); 41 }; 42 43 44 class M3uReader : public PlaylistFileReader { 45 public: 46 virtual void AppendToPlaylist(const entry_ref& ref, Playlist* playlist); 47 }; 48 49 50 class PlsReader : public PlaylistFileReader { 51 public: 52 virtual void AppendToPlaylist(const entry_ref& ref, 53 Playlist* playlist); 54 private: 55 status_t _ParseTitleLine(const BString& title, Playlist* playlist, 56 const int32 lastAssignedIndex); 57 status_t _ParseLengthLine(const BString& length, Playlist* playlist, 58 const int32 lastAssignedIndex); 59 }; 60 61 62 #endif 63