From 74f038a857dbfdb890233beb5dfd408ddbb0f73a Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Fri, 18 Oct 2024 11:06:58 +0800 Subject: [PATCH] =?utf8?q?#1029,=E8=A7=A3=E5=86=B3=EF=BC=8C=E6=89=8B?= =?utf8?q?=E8=A1=A8=EF=BC=8CiOS=EF=BC=8C=E6=89=8B=E6=9C=BA=E6=92=AD?= =?utf8?q?=E6=94=BE=E9=9F=B3=E4=B9=90=EF=BC=8C=E6=89=8B=E8=A1=A8=E4=BD=BF?= =?utf8?q?=E7=94=A8AI=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=89=8B=E8=A1=A8?= =?utf8?q?=E4=BE=9D=E7=84=B6=E5=9C=A8=E6=92=AD=E6=94=BE=E9=9F=B3=E4=B9=90?= =?utf8?q?=EF=BC=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/aivoice/src/AiVoiceModel.cpp | 7 ++-- .../nativeui/aivoice/src/AiVoicePresenter.cpp | 25 +++++++++----- .../nativeui/player/include/PlayersModel.h | 5 ++- .../nativeui/player/src/PlayersModel.cpp | 34 +++++++++++++++++++ 4 files changed, 58 insertions(+), 13 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp index f55bc2aba..82294acd4 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-20 15:14:50 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-10-17 10:18:24 + * @LastEditTime: 2024-10-17 15:19:15 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp */ #include "aivoice/include/AiVoiceModel.h" @@ -728,7 +728,8 @@ namespace OHOS } static void ai_start_screen60s_timer_callback(int data) { - GraphicService::GetInstance()->PostGraphicEvent(std::bind(ai_start_screen60s_timer_callbackProc, data)); + // GraphicService::GetInstance()->PostGraphicEvent(std::bind(ai_start_screen60s_timer_callbackProc, data)); + ai_start_screen60s_timer_callbackProc(data); } void AiVoiceModel::ai_start_screen60s_timer(uint32_t interval) { @@ -782,8 +783,8 @@ namespace OHOS } void AiVoiceModel::reset_ai_screen60s_timer_time() { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "reset_ai_screen60s_timer_time"); SCREEN_60S_TIME = 60; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "reset_ai_screen60s_timer_time %d",SCREEN_60S_TIME); if (nullptr == g_screen60s_timer) { ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 重新常亮屏 diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp index 6ae30d7c9..dad5bf0b6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-20 15:11:17 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-10-16 18:29:25 + * @LastEditTime: 2024-10-18 10:58:29 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp */ #include "AppViewIDs.h" @@ -23,9 +23,11 @@ #include "gfx_utils/mem_check.h" #include "bleService.h" +#include "player/include/PlayersModel.h" namespace OHOS { +#define BLE_CONNECT_INTERVAL_HIGH_AI 10 // 当前Presenter属性实例化的内存指针 static AiVoicePresenter *g_pAiVoicePresenter = nullptr; @@ -60,7 +62,7 @@ namespace OHOS // 开启一个60s取消长亮屏timer model->ai_start_screen60s_timer(); - uapi_ble_connect_param_update(10); + uapi_ble_connect_param_update(BLE_CONNECT_INTERVAL_HIGH_AI); } // 页面已经展示后的调用逻辑 @@ -93,7 +95,7 @@ namespace OHOS model->stop_listening_timer(); model->stop_ai_isready_timer(); - uapi_ble_connect_param_update(50); + uapi_ble_connect_param_update(BLE_CONNECT_INTERVAL_SLOW); } /*调转到返回结果界面*/ @@ -118,8 +120,8 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::ChangeToAIVoiceListeningView"); if (view_->GetAiVoiceScrollView(AIVOICE_AIMODE_CONNECTING) != nullptr && view_->GetAiVoiceScrollView(AIVOICE_AIMODE_CONNECTING)->IsVisible()) { - model->stop_ai_isready_timer();// 停止定时器 - if (val) /*如果查询的AI模型可用跳转到聆听中界面*/ + model->stop_ai_isready_timer(); // 停止定时器 + if (val) /*如果查询的AI模型可用跳转到聆听中界面*/ { ChangeViewAndLogicOperator(AIVOICE_AIMODE_CONNECTING, AIVOICE_LISTENING_VIEWID); } @@ -161,7 +163,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiModelsPresenter::index = %d", index); model->SetSelectAiModel(index); view_->ChangeAiModelAndUpdateComponentsStatus(); - model->reset_ai_screen60s_timer_time();//重置60s取消常亮屏timer + model->reset_ai_screen60s_timer_time(); // 重置60s取消常亮屏timer return; } @@ -203,6 +205,9 @@ namespace OHOS return false; } + /* ------------------------ 进行界面切换的时候重置60s取消常亮屏timer ------------------------ */ + model->reset_ai_screen60s_timer_time(); + /* -------------------------------------------------------------------------- */ view_->ChangeView(hideView, showView); // 默认先进行视图切换 switch (hideView) @@ -215,7 +220,7 @@ namespace OHOS } else if (showView == AIVOICE_AIMODE_CONNECTING) { - model->start_ai_isready_timer();/*开启一个查询AI模型是否连接成功定时器*/ + model->start_ai_isready_timer(); /*开启一个查询AI模型是否连接成功定时器*/ } break; @@ -304,6 +309,7 @@ namespace OHOS } else if (viewId == AIVOICE_START_CHAT_BUTTON_VIEW_ID) // 如果点击的是开始对话按钮 { + PlayersModel::GetInstance()->HandPausePhoneMusci(); // 暂停手机音乐 /* * 进入对话流程: * 1.当手表4G网络正常+与app连接正常 -> 通过4G调用大模型 @@ -350,9 +356,10 @@ namespace OHOS auto it = viewIdMap.find(viewId); if (it != viewIdMap.end()) { - if(it->first == AIVOICERETURNRESULTTEXT_CONTINUECHAT_BUTTON_VIEW_ID) //点击继续对话按钮要发取消当前对话指令,避免AI回应中途按继续对话按钮没有取消上一次对话问题 + if (it->first == AIVOICERETURNRESULTTEXT_CONTINUECHAT_BUTTON_VIEW_ID) // 点击继续对话按钮要发取消当前对话指令,避免AI回应中途按继续对话按钮没有取消上一次对话问题 { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CancelCurAIChat"); + PlayersModel::GetInstance()->HandPausePhoneMusci(); // 暂停手机音乐 AiVoiceModel::GetInstance().CancelCurAIChat(); } ChangeViewAndLogicOperator(it->second.first, it->second.second); @@ -387,7 +394,7 @@ namespace OHOS return false; } - model->reset_ai_screen60s_timer_time();//重置60s取消常亮屏timer + model->reset_ai_screen60s_timer_time(); // 重置60s取消常亮屏timer if (event.GetDragDirection() == DragEvent::DIRECTION_RIGHT_TO_LEFT) /*左滑*/ { 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 c02c6ea8c..793e13b49 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-28 14:58:16 + * @LastEditTime: 2024-10-18 10:55:54 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersModel.h */ @@ -111,6 +111,9 @@ public: void get_avrcp_ct_get_element_attributes(void); void set_player_state(bool value); bool get_player_state(); + bool get_a2dp_sink_connect_state(void); + void HandPausePhoneMusci(void); + void HandPlayPhoneMusci(void); // /* -------------------------------------------------------------------------- */ std::unordered_map> &getIdToMusicNameMap(void); std::string getRealMusicNameById(int id); 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 64f477812..62a81ba1f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp @@ -21,6 +21,7 @@ #include "MainViewSample.h" #include "settings/include/SettingModel.h" #include "bluetooth/include/BluetoothHeadsetEvent.h" +#include namespace OHOS { static constexpr int VOLUME_MAXIMUM = 100; @@ -995,6 +996,39 @@ bool PlayersModel::GetCurrentMusicIsPlaying(void) return false; } + // 获取手机音乐播放状态 + bool PlayersModel::get_a2dp_sink_connect_state(void) + { + bd_addr_t active_bd_addr = a2dp_snk_get_active_device(); + int state = a2dp_snk_get_playing_state(&active_bd_addr); + if (state == A2DP_IS_PLAYING) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "A2DP_IS_PLAYING"); + return true; + } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "A2DP_NOT_PLAYING"); + return false; + } + + + //暂停播放手机音乐 + void PlayersModel::HandPausePhoneMusci(void) + { + if (get_avrcp_ct_or_tg_is_connected() && get_a2dp_sink_connect_state()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AVRCP_KEY_PAUSE"); + set_phone_music_play_state(AVRCP_KEY_PAUSE); // 控制手机音乐暂停 + } + } + + //播放手机音乐 + void PlayersModel::HandPlayPhoneMusci(void) + { + if (get_avrcp_ct_or_tg_is_connected() && get_a2dp_sink_connect_state()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AVRCP_KEY_PLAY"); + set_phone_music_play_state(AVRCP_KEY_PLAY); // 控制手机音乐暂停 + } + } //用来控制手机音乐的播放,暂停,下一首,上一首音乐 void PlayersModel::set_phone_music_play_state(avrcp_key_operation_t notify) { -- 2.17.1