xref: /MusicPlayer2/MusicPlayer2/Playlist.h (revision 443d2d2511be730d1b1dd3181942b7fa6539aa1a)
1 #pragma once
2 #include "SongInfo.h"
3 class CPlaylistFile
4 {
5 public:
6     enum Type           //播放列表格式
7     {
8         PL_PLAYLIST,    //MusicPlayer2播放列表
9         PL_M3U,         //m3u播放列表
10         PL_M3U8         //m3u8播放列表
11     };
12 
13     CPlaylistFile();
14     ~CPlaylistFile();
15     void LoadFromFile(const wstring& file_path);
16     void SaveToFile(const wstring& file_path, Type type = PL_PLAYLIST) const;
17     const vector<SongInfo>& GetPlaylist() const;
18     int AddSongsToPlaylist(const vector<SongInfo>& songs, bool insert_begin = false);
19     // 使用移动语义覆盖参数song_list,调用后此CPlaylistFile对象不再可用
20     void MoveToSongList(vector<SongInfo>& song_list);
21     bool IsSongInPlaylist(const SongInfo& song);
22     int GetSongIndexInPlaylist(const SongInfo& song);
23     void RemoveSong(const SongInfo& song);
24 
25     static bool IsPlaylistFile(const wstring& file_path);
26     static bool IsPlaylistExt(wstring ext);
27 
28     static void SavePlaylistToFile(const vector<SongInfo>& song_list, const wstring& file_path, Type type = PL_PLAYLIST);
29 public:
30     const static vector<wstring> m_surpported_playlist;     //支持的播放列表文件的扩展名列表
31 
32 private:
33     void DisposePlaylistFileLine(const string& str_current_line, bool utf8);
34 
35 private:
36     vector<SongInfo> m_playlist;
37     wstring m_path;
38 };
39 
40