From: luozheng <1732036298@qq.com> Date: Sat, 28 Sep 2024 07:42:59 +0000 (+0800) Subject: 解决切换到手机音乐还可以播放本地音乐bug X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=5bae8d217f836b91ba96ed61f3fcbab6b029dccc;p=mirrors%2FFD230.git 解决切换到手机音乐还可以播放本地音乐bug --- 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 8ce15f274..c02c6ea8c 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-26 14:21:11 + * @LastEditTime: 2024-09-28 14:58:16 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersModel.h */ @@ -110,6 +110,7 @@ public: void set_phone_music_play_state(avrcp_key_operation_t notify); void get_avrcp_ct_get_element_attributes(void); void set_player_state(bool value); + bool get_player_state(); // /* -------------------------------------------------------------------------- */ std::unordered_map> &getIdToMusicNameMap(void); std::string getRealMusicNameById(int id); @@ -120,6 +121,7 @@ public: void showIdToMusicNameMapData(void); // /* -------------------------------------------------------------------------- */ private: + bool phonePlayButtonState{false}; bool musicSourceFlag{false};//音乐来源标志:false:默认为手表音乐,true:手机音乐 int64_t playerCurrentTime_{0}; int64_t playerMusicDuration_{0}; 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 95fa0d413..aefa17d3e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp @@ -1032,11 +1032,16 @@ bool PlayersModel::GetCurrentMusicIsPlaying(void) { PlayersPresenter *playersPresenter = PlayersPresenter::GetInstance(); if (playersPresenter != nullptr) - { + { + phonePlayButtonState = value; playersPresenter->SetPhonePlayerState(value); } } + bool PlayersModel::get_player_state() + { + return phonePlayButtonState; + } std::unordered_map> &PlayersModel::getIdToMusicNameMap(void) { return idToMusicNameMap; 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 67badc2e2..3c7f2bbf0 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersPresenter.cpp @@ -606,14 +606,6 @@ void ButtonOnClickListener::PlayerButtonOnClick() return; } - if(PlayersListGroup::GetInstance()->GetCase().IsEmpty() && !PlayersModel::GetInstance()->GetMusicSource()) //若当前歌曲列表为空且为本地音乐他跳转到音乐列表进行提示 - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "current playersCaseList_ is empty!!"); - playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::UNSELECTED); - playersView->ChangeView(PlayersView::MAIN_MUSICPLAYER_VIEW,PlayersView::MUSIC_LIST_VIEW); - return; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "play_or_pause_Button OnClick"); uint8_t state = UICheckBox::UICheckBoxState::MAX_STATUS_NUM; int32_t playerState; @@ -641,29 +633,47 @@ void ButtonOnClickListener::PlayerButtonOnClick() WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[PlayerButtonOnClick] calling phone"); return; } - /* -------------------------- 若ct或tg端是已连接状态且当前为手机音乐 ------------------------- */ - if(PlayersModel::GetInstance()->get_avrcp_ct_or_tg_is_connected() && PlayersModel::GetInstance()->GetMusicSource()) + + if( !PlayersModel::GetInstance()->GetMusicSource()) { - if (state == UICheckBox::UICheckBoxState::SELECTED) + if(PlayersListGroup::GetInstance()->GetCase().IsEmpty()) //若当前歌曲列表为空且为本地音乐他跳转到音乐列表进行提示 { - PlayersModel::GetInstance()->set_phone_music_play_state(AVRCP_KEY_PLAY); //控制手机音乐播放 - } - else if (state == UICheckBox::UICheckBoxState::UNSELECTED) + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "current playersCaseList_ is empty!!"); + playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::UNSELECTED); + playersView->ChangeView(PlayersView::MAIN_MUSICPLAYER_VIEW,PlayersView::MUSIC_LIST_VIEW); + return; + } + else { - PlayersModel::GetInstance()->set_phone_music_play_state(AVRCP_KEY_PAUSE);//控制手机音乐暂停 + if (state == UICheckBox::UICheckBoxState::SELECTED) { + /* start play */ + PlayersModel::GetInstance()->ConnectBtAndLocalPlay(connCtState, connTgState, playerState); + } else if (state == UICheckBox::UICheckBoxState::UNSELECTED) { + PlayersModel::GetInstance()->ConnectBtAndLocalPause(connCtState, connTgState); + } + PlayersModel::GetInstance()->SetCurrentIndex(PlayersModel::GetInstance()->GetCurrentIndex()); } - return; } - /* -------------------------------------------------------------------------- */ - - if (state == UICheckBox::UICheckBoxState::SELECTED) { - /* start play */ - PlayersModel::GetInstance()->ConnectBtAndLocalPlay(connCtState, connTgState, playerState); - } else if (state == UICheckBox::UICheckBoxState::UNSELECTED) { - PlayersModel::GetInstance()->ConnectBtAndLocalPause(connCtState, connTgState); + else //手机音乐 + { + /* -------------------------- 若ct或tg端是已连接状态且当前为手机音乐 ------------------------- */ + if(PlayersModel::GetInstance()->get_avrcp_ct_or_tg_is_connected()) + { + if (state == UICheckBox::UICheckBoxState::SELECTED) + { + PlayersModel::GetInstance()->set_phone_music_play_state(AVRCP_KEY_PLAY); //控制手机音乐播放 + } + else if (state == UICheckBox::UICheckBoxState::UNSELECTED) + { + PlayersModel::GetInstance()->set_phone_music_play_state(AVRCP_KEY_PAUSE);//控制手机音乐暂停 + } + return; + } + else + { + playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::UNSELECTED); + } } - /* -------------------------------------------------------------------------- */ - PlayersModel::GetInstance()->SetCurrentIndex(PlayersModel::GetInstance()->GetCurrentIndex()); } /*下一首按钮被点击时调用*/ void ButtonOnClickListener::NextButtonOnClick() @@ -1595,7 +1605,6 @@ void PlayersPresenter::SetPhonePlayerState(bool value) { PlayersView *playersView = PlayersView::GetInstance(); if (playersView != nullptr) { - PlayersModel::GetInstance()->SetPlayButtonState(value); playersView->SetPlayerButtonState(value ? UICheckBox::UICheckBoxState::SELECTED:UICheckBox::UICheckBoxState::UNSELECTED); } return; diff --git a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersView.cpp b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersView.cpp index 21dfa9d03..322095cf3 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersView.cpp @@ -872,6 +872,8 @@ namespace OHOS /* -------------------------------------------------------------------------- */ if (musicSourceType) // 如果切換到手机音乐,且当前在放歌,就停止音乐 { + bool value = PlayersModel::GetInstance()->get_player_state(); + SetPlayerButtonState(value ? UICheckBox::UICheckBoxState::SELECTED:UICheckBox::UICheckBoxState::UNSELECTED); /*停止音乐*/ StopCurPlayingMusic(); }