From 813a2a504c7c710f3c2a1cc386157de700355c91 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Tue, 24 Sep 2024 15:55:28 +0800 Subject: [PATCH] =?utf8?q?1.=E9=9F=B3=E4=B9=90=E6=92=AD=E6=94=BE=E5=99=A8?= =?utf8?q?=E6=B7=BB=E5=8A=A0=EF=BC=8C=E6=96=87=E4=BB=B6=E5=90=8D=E4=B8=BA1?= =?utf8?q?6=E8=BF=9B=E5=88=B6=E5=AD=97=E7=AC=A6=E4=B8=B2=EF=BC=8C=E6=98=BE?= =?utf8?q?=E7=A4=BA=E4=B8=BA=E6=AD=A3=E5=B8=B8UTF-8=E5=AD=97=E7=AC=A6?= =?utf8?q?=E4=B8=B2=E5=8A=9F=E8=83=BD=202.=E6=B7=BB=E5=8A=A0=E5=AF=B9?= =?utf8?q?=E5=BA=94id=E4=B8=8E=E9=9F=B3=E4=B9=90=E6=96=87=E4=BB=B6?= =?utf8?q?=E5=90=8D=E4=BA=92=E6=9F=A5=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/player/include/PlayersModel.h | 11 +++- .../player/include/PlayersPresenter.h | 4 +- .../player/src/PlayerListDelSongView.cpp | 4 +- .../player/src/PlayersCaseListAdapter.cpp | 3 +- .../nativeui/player/src/PlayersModel.cpp | 59 ++++++++++++++++++- .../nativeui/player/src/PlayersPresenter.cpp | 9 +++ 6 files changed, 84 insertions(+), 6 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersModel.h b/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersModel.h index 1e0311269..931bae687 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersModel.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-08-05 15:20:03 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-09-23 16:04:25 + * @LastEditTime: 2024-09-24 14:25:27 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersModel.h */ @@ -109,11 +109,20 @@ public: bool get_avrcp_ct_or_tg_is_connected(void); void set_phone_music_play_state(avrcp_key_operation_t notify); void set_player_state(bool value); + // /* -------------------------------------------------------------------------- */ + std::unordered_map> &getIdToMusicNameMap(void); + std::string getMusicNameById(int id); + uint16_t getIdFromMusicName(const std::string &musicName); + std::string getHexMusicNameFromMusicName(const std::string &musicName); + int getIdToMusicNameMapNumber(void); + void showIdToMusicNameMapData(void); + // /* -------------------------------------------------------------------------- */ private: bool musicSourceFlag{false};//音乐来源标志:false:默认为手表音乐,true:手机音乐 int64_t playerCurrentTime_{0}; int64_t playerMusicDuration_{0}; int64_t playerProgressValue_{0}; + std::unordered_map> idToMusicNameMap;//> private: PlayersCaseListAdapter *m_PlayersCaseListAdapter{nullptr}; int64_t duration_{0}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersPresenter.h index 0d7035bc9..b41ca0005 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersPresenter.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-08-05 15:20:03 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-09-23 20:24:49 + * @LastEditTime: 2024-09-24 15:01:01 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersPresenter.h */ @@ -92,6 +92,8 @@ private: std::list playersList_; //音乐列表 int GetAllFiles(std::list &playersList); void sortPlayersCaseList(std::list* playersCaseList); + std::string filename; + std::string hexfilename; }; // Button OnClick diff --git a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayerListDelSongView.cpp b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayerListDelSongView.cpp index 14ed7b85d..a245181a7 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayerListDelSongView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayerListDelSongView.cpp @@ -90,7 +90,7 @@ namespace OHOS delSongName = songName; if (songNameLabel != nullptr) { - songNameLabel->SetText(songName); + songNameLabel->SetText(PlayersModel::GetInstance()->getHexMusicNameFromMusicName(songName).c_str()); songNameLabel->Invalidate(); } } @@ -98,7 +98,7 @@ namespace OHOS // 删除歌曲文件 void PlayerListDelSongView::DeleteSongNameFile(void) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " whill Deleted file:%s", delSongName.c_str()); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " whill Deleted file:%s", delSongName.c_str()); std::string path = PlayersModel::GetInstance()->GetMusicPlayPath() + "/" + delSongName; if (uapi_delete_files(path.c_str())) diff --git a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersCaseListAdapter.cpp b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersCaseListAdapter.cpp index d18815c8b..3c176d895 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersCaseListAdapter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersCaseListAdapter.cpp @@ -147,7 +147,8 @@ namespace OHOS node = node->next_; } /* -------------------------------------------------------------------------- */ - std::string strSongName = node->data_.sliceId; + // std::string strSongName = node->data_.sliceId; + std::string strSongName = PlayersModel::GetInstance()->getHexMusicNameFromMusicName(node->data_.sliceId); std::string pureName = strSongName.substr(0, strSongName.rfind(".")); const char *songName = pureName.c_str(); // 获取纯净歌曲名 /* -------------------------------------------------------------------------- */ diff --git a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp index c5997ec65..5dcf570ef 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp @@ -753,7 +753,7 @@ void PlayersModel::GetDuration(int64_t &duration) duration = duration_; } -/*创建音乐播放路径*/ +/*创建音乐播放路径,不存在就创建*/ bool PlayersModel::CreateMusicPlayDirectory(const char* path) { if (access(path, F_OK) == -1) { // 如果路径不存在 @@ -1028,6 +1028,63 @@ bool PlayersModel::GetCurrentMusicIsPlaying(void) playersPresenter->SetPhonePlayerState(value); } } + + std::unordered_map> &PlayersModel::getIdToMusicNameMap(void) + { + return idToMusicNameMap; + } + + //根据id获取名字 + std::string PlayersModel::getMusicNameById(int id) + { + for (const auto &entry : idToMusicNameMap) + { + if (entry.first == id) + { + return entry.second.first; // 返回对应音乐名 + } + } + return ""; + } + //根据名字获取id + uint16_t PlayersModel::getIdFromMusicName(const std::string &musicName) + { + for (const auto &entry : idToMusicNameMap) + { + if (entry.second.first == musicName) + { + return entry.first; // 返回对应ID + } + } + return 0; + } + + //根据16进制文件名查找对应的UTF-8文件名 + std::string PlayersModel::getHexMusicNameFromMusicName(const std::string &musicName) + { + for (const auto &entry : idToMusicNameMap) + { + if (entry.second.first == musicName) + { + return entry.second.second; // 返回对应音乐名 + } + } + return ""; + } + + //获取 idToMusicNameMap 的 zize 大小 + int PlayersModel::getIdToMusicNameMapNumber(void) + { + return idToMusicNameMap.size(); + } + + void PlayersModel::showIdToMusicNameMapData(void) + { + for (const auto &entry : idToMusicNameMap) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "id = %d name.first = %s name.second = %s", entry.first,entry.second.first.c_str(),entry.second.second.c_str()); + } + } } #ifdef __cplusplus diff --git a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersPresenter.cpp index 55b4c5e10..67badc2e2 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersPresenter.cpp @@ -429,6 +429,10 @@ void PlayersListGroup::SetUpListCase() } playersCaseList_->Clear(); playersList_.clear(); + if(!PlayersModel::GetInstance()->getIdToMusicNameMap().empty()) + { + PlayersModel::GetInstance()->getIdToMusicNameMap().clear();//清空map + } if(!PlayersModel::GetInstance()->CreateMusicPlayDirectory()) { return; @@ -456,6 +460,7 @@ void PlayersListGroup::SetUpListCase() WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "musicName = %s,index = %d",playerCaseInfo.sliceId,playerCaseInfo.index); playersCaseList_->PushBack(playerCaseInfo); } + PlayersModel::GetInstance()->showIdToMusicNameMapData(); } List& PlayersListGroup::GetCase() @@ -546,6 +551,10 @@ int PlayersListGroup::GetAllFiles(std::list &playersList) // 遍历文件 if (dirp != NULL) { while ((direntp = readdir(dirp)) != NULL) { + filename = direntp->d_name; + hexfilename = hex_to_string(direntp->d_name); + PlayersModel::GetInstance()->getIdToMusicNameMap()[i].first = filename; //16进制的文件名 + PlayersModel::GetInstance()->getIdToMusicNameMap()[i].second = hexfilename; //转成UTF-8的文件名 ret = memcpy_s(playerCaseInfo.sliceId, DEC_NUM_256, direntp->d_name, DEC_NUM_256); if (ret != OHOS_SUCCESS) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "memcpy_s err %d.", ret); -- 2.17.1