From d7ea59f9725b51ccc4f271dc759796f73e02b724 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Fri, 6 Dec 2024 10:38:39 +0800 Subject: [PATCH] =?utf8?q?=E8=A7=A3=E5=86=B3=E6=89=8B=E6=9C=BAAPP=E6=89=B9?= =?utf8?q?=E9=87=8F=E5=88=A0=E9=99=A4=E6=9C=AC=E5=9C=B0=E9=9F=B3=E4=B9=90?= =?utf8?q?=E6=97=B6=EF=BC=8C=E5=BD=93=E5=89=8D=E6=AD=A3=E5=9C=A8=E6=92=AD?= =?utf8?q?=E6=94=BE=E7=9A=84=E9=9F=B3=E4=B9=90UI=E7=8A=B6=E6=80=81?= =?utf8?q?=E8=A2=AB=E6=94=B9=E5=8F=98=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../player/include/PlayerListDelSongView.h | 5 ++-- .../nativeui/player/include/PlayersModel.h | 6 ++++- .../player/src/PlayerListDelSongView.cpp | 16 +----------- .../player/src/PlayersCaseListAdapter.cpp | 5 ++-- .../nativeui/player/src/PlayersModel.cpp | 25 +++++++++++++++++++ 5 files changed, 36 insertions(+), 21 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayerListDelSongView.h b/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayerListDelSongView.h index 9e8c3c976..f98e1b770 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayerListDelSongView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayerListDelSongView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-08-05 15:20:03 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-12-05 21:03:56 + * @LastEditTime: 2024-12-05 21:50:19 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayerListDelSongView.h */ @@ -44,7 +44,7 @@ namespace OHOS virtual ~PlayerListDelSongView(); static PlayerListDelSongView *GetInstance(void); UIViewGroup *CreatePlayerListDelSongView(); - void SetTheDelSongLabelStyle(const char *songName,int index); + void SetTheDelSongLabelStyle(const char *songName); void DeleteSongNameFile(void); UIButton *GetEnsureDeleteButton(void); UIButton *GetCancelDeleteButton(void); @@ -65,7 +65,6 @@ namespace OHOS UIButton *cancelDeleteButton{nullptr}; std::string delSongName; - int deleteSongIndex{0}; UIView::OnDragListener *dragListener{nullptr}; UIView::OnClickListener *buttonClickListener{nullptr}; 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 3ece4e202..9710ac9da 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-11-28 11:04:43 + * @LastEditTime: 2024-12-05 21:56:01 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersModel.h */ @@ -114,12 +114,15 @@ public: bool get_a2dp_sink_playing_state(void); void HandPausePhoneMusic(void); void HandPlayPhoneMusic(void); + std::string getcurrentplayingmusicname(void); + void setcurrentplayingmusicname(std::string name); // /* -------------------------------------------------------------------------- */ std::unordered_map> &getIdToMusicNameMap(void); std::string getRealMusicNameById(int id); std::string getShowMusicNameById(int id); uint16_t getIdFromMusicName(const std::string &musicName); std::string getHexMusicNameFromMusicName(const std::string &musicName); + std::string getMusicNameFromHexMusicName(const std::string &musicName); int getIdToMusicNameMapNumber(void); void showIdToMusicNameMapData(void); int getPreShowView(void); @@ -153,6 +156,7 @@ private: void RandomPlayout(void); void NextSong(int16_t index); int16_t currentIndex{0}; //当前在播哪一首歌的索引 + std::string currentplayingmusicname; //当前在播哪一首歌的名称 int16_t playerModel{0}; char *currentSongName{nullptr}; bool isStopAndReset{false}; 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 37508333a..b0407411e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayerListDelSongView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayerListDelSongView.cpp @@ -85,10 +85,9 @@ namespace OHOS /// @brief 设置歌曲名标签样式 /// @param songName 歌曲名 - void PlayerListDelSongView::SetTheDelSongLabelStyle(const char *songName,int index) + void PlayerListDelSongView::SetTheDelSongLabelStyle(const char *songName) { delSongName = songName; - deleteSongIndex = index; if (songNameLabel != nullptr) { songNameLabel->SetText(PlayersModel::GetInstance()->getHexMusicNameFromMusicName(songName).c_str()); @@ -105,19 +104,6 @@ namespace OHOS if (uapi_delete_files(path.c_str())) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Deleted file: %s successed!", path.c_str()); - int index = PlayersModel::GetInstance()->GetCurrentIndex(); - if(deleteSongIndex < index) - { - if(index - 1 < 0) - { - index = 0; - } - else - { - index--; - } - PlayersModel::GetInstance()->SetCurrentIndex(index); - } } else { 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 9fc2d1280..18f5e2be7 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersCaseListAdapter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersCaseListAdapter.cpp @@ -56,7 +56,7 @@ namespace OHOS playersView->ChangeView(PlayersView::MUSIC_LIST_VIEW, PlayersView::MUSIC_DELETE_VIEW); if (playersView->GetPlayerListDelSongView()) { - playersView->GetPlayerListDelSongView()->SetTheDelSongLabelStyle(musicPlayName, view.GetViewIndex()); + playersView->GetPlayerListDelSongView()->SetTheDelSongLabelStyle(musicPlayName); } return true; } @@ -75,6 +75,7 @@ namespace OHOS std::string strSrcMusic(APP_MUSIC_PATH); std::string tempStr("/"); std::string strName = musicPlayName; + PlayersModel::GetInstance()->setcurrentplayingmusicname(musicPlayName); PlayersModel::GetInstance()->SetPlayerUri(strSrcMusic + tempStr + strName); // 设置播放路径Uri state = playersView->GetPlayerButtonState(); @@ -172,7 +173,7 @@ namespace OHOS { item = static_cast(inView); } - if (PlayersModel::GetInstance()->GetCurrentIndex() == index && PlayersModel::GetInstance()->GetCurrentMusicIsPlaying()) + if (PlayersModel::GetInstance()->getcurrentplayingmusicname() == node->data_.sliceId && PlayersModel::GetInstance()->GetCurrentMusicIsPlaying()) { item->UpdateItemViewStyle(true); } 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 1cde3a627..7dd2ad83f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp @@ -250,6 +250,7 @@ int PlayersModel::PlayerInit(void) char strFile[BUFFER_SIZE] = "No music files"; sliceId = strFile; } + currentplayingmusicname = sliceId;//记录当前播放的歌曲的名称 std::string strSongName = sliceId; std::string pureName = strSongName.substr(0, strSongName.rfind(".")); const char *songName = pureName.c_str(); @@ -279,6 +280,7 @@ void PlayersModel::NextSong(int16_t index) WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetCase %d sliceId err!!!", index); return; } + currentplayingmusicname = sliceId;//记录当前播放的歌曲的名称 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetCase sliceId %s.", sliceId); std::string strSrcMusic(APP_MUSIC_PATH); std::string tempStr("/"); @@ -1129,6 +1131,19 @@ bool PlayersModel::GetCurrentMusicIsPlaying(void) } return ""; } + + //根据UTF-8文件名查找对应的16进制文件名 + std::string PlayersModel::getMusicNameFromHexMusicName(const std::string &musicName) + { + for (const auto &entry : idToMusicNameMap) + { + if (entry.second.second == musicName) + { + return entry.second.first; // 返回对应音乐名 + } + } + return ""; + } //获取 idToMusicNameMap 的 zize 大小 int PlayersModel::getIdToMusicNameMapNumber(void) @@ -1151,6 +1166,16 @@ bool PlayersModel::GetCurrentMusicIsPlaying(void) { preshowView = index; } + //获取当前播放的音乐名字 + std::string PlayersModel::getcurrentplayingmusicname() + { + return currentplayingmusicname; + } + //设置当前播放的音乐名字 + void PlayersModel::setcurrentplayingmusicname(std::string name) + { + currentplayingmusicname = name; + } } #ifdef __cplusplus -- 2.17.1