1 #pragma once 2 #include <map> 3 #include "MediaLibHelper.h" 4 5 class CUiMediaLibItemMgr 6 { 7 public: 8 ~CUiMediaLibItemMgr(); 9 static CUiMediaLibItemMgr& Instance(); 10 11 void Init(); 12 13 int GetItemCount(CMediaClassifier::ClassificationType type) const; //获取指定类别下项目的数量 14 std::wstring GetItemDisplayName(CMediaClassifier::ClassificationType type, int index) const; //获取指定类别下项目显示到界面中的名称 15 const std::wstring& GetItemName(CMediaClassifier::ClassificationType type, int index) const; //获取指定项的原始名称,如果是<未知xxx>返回的是空 16 int GetItemSongCount(CMediaClassifier::ClassificationType type, int index) const; //获取指定类别下项目的曲目数量 17 void SetCurrentName(CMediaClassifier::ClassificationType type, const std::wstring& name); //设置指定类别下正在播放项目的名称,其中name为原始名称 18 int GetCurrentIndex(CMediaClassifier::ClassificationType type); //获取指定类别下正在播放项目的序号 19 20 private: 21 CUiMediaLibItemMgr(); 22 void GetClassifiedMeidaLibItemList(CMediaClassifier::ClassificationType type); 23 24 static CUiMediaLibItemMgr m_instance; 25 struct ItemInfo 26 { 27 std::wstring name; 28 int count{}; 29 }; 30 31 const ItemInfo& GetItemInfo(CMediaClassifier::ClassificationType type, int index) const; 32 33 std::map<CMediaClassifier::ClassificationType, std::vector<ItemInfo>> m_item_map; //保存媒体库中所有分类的名称列表 34 bool m_loading{}; 35 std::map<CMediaClassifier::ClassificationType, int> m_current_index_map; //保存媒体库模式下每种模式正在播放的曲目 36 std::map<CMediaClassifier::ClassificationType, std::wstring> m_current_name_map; //保存媒体库模式下每种模式正在播放的曲目 37 mutable std::shared_mutex m_shared_mutex; 38 }; 39 40 41 class CUiMyFavouriteItemMgr 42 { 43 public: 44 ~CUiMyFavouriteItemMgr(); 45 static CUiMyFavouriteItemMgr& Instance(); 46 47 int GetSongCount() const; 48 const SongInfo& GetSongInfo(int index) const; 49 void UpdateMyFavourite(); 50 bool IsLoading() const { return m_loading; } 51 void GetSongList(std::vector<SongInfo>& song_list) const; 52 bool Contains(const SongInfo& song) const; 53 54 private: 55 CUiMyFavouriteItemMgr(); 56 static CUiMyFavouriteItemMgr m_instance; 57 58 vector<SongInfo> m_may_favourite_song_list; //“我喜欢的音乐”列表 59 bool m_loading{}; 60 mutable std::shared_mutex m_shared_mutex; 61 62 }; 63 64 65 class CUiAllTracksMgr 66 { 67 public: 68 ~CUiAllTracksMgr(); 69 static CUiAllTracksMgr& Instance(); 70 71 //用于在UI中显示的曲目信息 72 struct UTrackInfo 73 { 74 SongKey song_key; 75 std::wstring name; 76 Time length; 77 bool is_favourite{}; 78 }; 79 80 int GetSongCount() const; 81 SongInfo GetSongInfo(int index) const; 82 const UTrackInfo& GetItem(int index) const; 83 int GetCurrentIndex() const; //获取正在播放的曲目在m_all_tracks_list中的序号 84 void SetCurrentSong(const SongInfo& song); //设置正在播放的曲目,将其在m_all_tracks_list中的序号保存起来 85 void UpdateAllTracks(); //从CSongDataManager中更新所有曲目信息 86 bool IsLoading() const { return m_loading; } 87 void GetSongList(std::vector<SongInfo>& song_list) const; 88 void AddOrRemoveMyFavourite(int index); //仅更新UI中显示的“我喜欢”的状态,不更新到“我喜欢的音乐”播放列表中 89 90 private: 91 CUiAllTracksMgr(); 92 static CUiAllTracksMgr m_instance; 93 94 std::vector<UTrackInfo> m_all_tracks_list; //所有曲目信息列表 95 bool m_loading{}; //如果正在初始化中,则为true 96 int m_current_index{ -1 }; //正在播放的曲目在m_all_tracks_list中的序号 97 bool m_inited{}; //如果已经初始化过,则为true 98 mutable std::shared_mutex m_shared_mutex; 99 }; 100