#1029,解决,手表,iOS,手机播放音乐,手表使用AI功能,手表依然在播放音乐,
authorluozheng <1732036298@qq.com>
Fri, 18 Oct 2024 03:06:58 +0000 (11:06 +0800)
committerluozheng <1732036298@qq.com>
Fri, 18 Oct 2024 03:06:58 +0000 (11:06 +0800)
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersModel.h
code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp

index f55bc2a..82294ac 100644 (file)
@@ -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); // 重新常亮屏
index 6ae30d7..dad5bf0 100644 (file)
@@ -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"
 
 #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) /*左滑*/
         {
index c02c6ea..793e13b 100644 (file)
@@ -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<uint16_t, std::pair<std::string,std::string>> &getIdToMusicNameMap(void);
     std::string getRealMusicNameById(int id);
index 64f4778..62a81ba 100644 (file)
@@ -21,6 +21,7 @@
 #include "MainViewSample.h"
 #include "settings/include/SettingModel.h"
 #include "bluetooth/include/BluetoothHeadsetEvent.h"
+#include <bts_a2dp_sink.h>
 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)
     {