From: luozheng <1732036298@qq.com> Date: Tue, 24 Sep 2024 07:55:28 +0000 (+0800) Subject: 1.音乐播放器添加,文件名为16进制字符串,显示为正常UTF-8字符串功能 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=813a2a504c7c710f3c2a1cc386157de700355c91;p=mirrors%2FFD230.git 1.音乐播放器添加,文件名为16进制字符串,显示为正常UTF-8字符串功能 2.添加对应id与音乐文件名互查接口 --- 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);