From 144a6d867d9faaf426b03df6aae6af7b7d09dccb Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Tue, 20 Aug 2024 18:07:03 +0800 Subject: [PATCH] =?utf8?q?1.=E9=9F=B3=E4=B9=90=E6=92=AD=E6=94=BE=E5=99=A8?= =?utf8?q?=E5=9C=A8=E5=88=87=E6=8D=A2=E9=80=9A=E9=81=93=E6=97=B6=E6=B7=BB?= =?utf8?q?=E5=8A=A0=E4=B8=BB=E5=8A=A8=E8=BF=9E=E6=8E=A5=E5=92=8C=E6=96=AD?= =?utf8?q?=E5=BC=80=E6=89=8B=E6=9C=BAa2dp=E5=8A=9F=E8=83=BD=202.=E6=92=AD?= =?utf8?q?=E6=94=BE=E5=99=A8=E6=B7=BB=E5=8A=A0=E8=BF=9E=E6=8E=A5=E5=8A=A8?= =?utf8?q?=E7=94=BB=EF=BC=8C=E6=89=8B=E8=A1=A8=E8=BF=9E=E6=8E=A5=E6=89=8B?= =?utf8?q?=E6=9C=BA=E9=9F=B3=E4=B9=90=E8=B6=85=E6=97=B6=E6=97=B6=E9=97=B4?= =?utf8?q?=E8=AE=BE=E7=BD=AE=E4=B8=BA5s?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/player/include/PlayersModel.h | 4 +- .../player/include/PlayersPresenter.h | 3 +- .../nativeui/player/include/PlayersView.h | 6 +- .../player/src/MusicPlayerSourceView.cpp | 17 ++-- .../nativeui/player/src/PlayersModel.cpp | 89 +++++++++++++++++++ .../nativeui/player/src/PlayersPresenter.cpp | 10 --- .../nativeui/player/src/PlayersView.cpp | 86 +++++++++++++----- .../nativeui/settings/src/SettingModel.cpp | 7 +- 8 files changed, 176 insertions(+), 46 deletions(-) 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 37be7a259..27b1d98a7 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-08-13 17:11:32 + * @LastEditTime: 2024-08-20 17:18:32 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersModel.h */ @@ -101,6 +101,8 @@ public: void SetMusicSource(bool value); void UpdateMusicPlayerList(void); bool GetCurrentMusicIsPlaying(void); + void PlayerMusic_StartTimer(uint32_t interval = 1000); + void PlayerMusic_StopTimer(void); private: bool musicSourceFlag{false};//音乐来源标志:false:默认为手表音乐,true:手机音乐 private: 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 519943b3e..31b761ebb 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-08-13 16:10:15 + * @LastEditTime: 2024-08-20 17:57:54 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersPresenter.h */ @@ -240,7 +240,6 @@ public: void OnClickSuccBack(void); void OnClickConnFailBack(void); void OnClickFailBack(void); - void UpdatePlayerView(bool musicSourceType, bool phoneMusicConnectStatus); void SetPlaybackProgress(int64_t value); void SetPlayerState(bool value); void PlayerbackReset(void); diff --git a/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersView.h b/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersView.h index d8b5f973a..5e1304da1 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-08-05 15:20:03 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-14 11:26:39 + * @LastEditTime: 2024-08-20 17:39:13 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersView.h */ @@ -34,6 +34,7 @@ #include "player/include/MusicPlayerSourceView.h" #include "player/include/MusicPlayerBluetoothDisConView.h" #include "player/include/MusicPlayerBTConnectFailedView.h" +#include "aivoice/include/AiVoiceConnectingView.h" namespace OHOS { #define PLAY_PROGRESS_MIN 0 @@ -98,7 +99,7 @@ namespace OHOS UICircleProgress *GetPlaybackProgress(void); UICheckBox::UICheckBoxState GetPlayerButtonState(void); - void UpdatePlayerView(bool musicSourceType, bool phoneMusicConnectStatus); + void UpdatePlayerView(void); void UpdateMusicListStatus(void); void OnClickBackKeyToMainMusicPlayerView(void); @@ -152,6 +153,7 @@ namespace OHOS UIViewGroup *musicListGroupView{nullptr}; // 音乐列表视图 MusicPlayerBluetoothDisConView *musicPlayerBluetoothDisConView{nullptr}; // 蓝牙未连接视图 MusicPlayerBTConnectFailedView *musicPlayerBTConnectFailedView{nullptr}; // 蓝牙连接失败视图 + AiVoiceConnectingView *musicPlayerConnectingView{nullptr}; // 连接动画 private: UIView::OnClickListener *clickListener{nullptr}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/player/src/MusicPlayerSourceView.cpp b/code/sdk/application/wearable/fd230app/nativeui/player/src/MusicPlayerSourceView.cpp index bb47b64d4..1bef02af6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/src/MusicPlayerSourceView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/player/src/MusicPlayerSourceView.cpp @@ -67,15 +67,16 @@ namespace OHOS // 1.a2dp未连接,向手机发起a2dp连接 // 如果蓝牙没连接直接是跳转到蓝牙连接失败视图,连接了就有一个主动去连手机的a2dp过程,5秒超市 - playersPresenter->UpdatePlayerView(PlayersModel::GetInstance()->GetMusicSource(), phonebluetoothcon && a2dp); - if (!phonebluetoothcon) { playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MUSIC_BLUETOOTH_DISCONN_VIEW); } - else if (phonebluetoothcon && !a2dp) + else if (phonebluetoothcon && !a2dp) // 如果手机蓝牙已连接但手表与手机的a2dp未连接手表主动去连接a2dp { - playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MUSIC_BT_CONNECTFAILED_VIEW); + /* -------------------------------------------------------------------------- */ + uapi_a2dp_snk_connect(); // 切换通道主动连接atdp + /* -------------------------------------------------------------------------- */ + playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MUISC_CONNECTING); } else if (phonebluetoothcon && a2dp) { @@ -87,8 +88,12 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnClick watchLableButton"); PlayersModel::GetInstance()->SetMusicSource(false); UpdateBluetoothHeadSetViewIsVisible(); - - playersPresenter->UpdatePlayerView(PlayersModel::GetInstance()->GetMusicSource(), phonebluetoothcon && a2dp); + /* -------------------------------------------------------------------------- */ + if (a2dp) + { + uapi_a2dp_snk_disconnect(); // 切换通道主动断开atdp + } + /* -------------------------------------------------------------------------- */ } else if (button == bluetoothHeadsetLableButton) { 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 3e2aa2c79..e2dd531dd 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp @@ -15,6 +15,9 @@ #include "bluetooth/include/BluetoothModel.h" #include #include +#include "cmsis_os.h" +#include +#include namespace OHOS { static constexpr int VOLUME_MAXIMUM = 100; @@ -801,6 +804,92 @@ bool PlayersModel::GetCurrentMusicIsPlaying(void) } return false; } + + /* -------------------------------------------------------------------------- */ + static osTimerId_t g_timer = NULL; + static int g_PlayerTimes = 5; + + static void PlayerMusic_TimerCallbackProc(int data) + { + g_PlayerTimes--; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "g_PlayerTimes = %d",g_PlayerTimes); + PlayersView *playersView = PlayersView::GetInstance(); + if (playersView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playersView nullptr err"); + return; + } + if(g_PlayerTimes < 0) /*5秒超时*/ + { + playersView->ChangeView(PlayersView::MUISC_CONNECTING, PlayersView::MUSIC_BT_CONNECTFAILED_VIEW); + } + else + { + bool a2dp = uapi_a2dp_snk_get_device_connect_state();// 获取a2dp连接状态 + if(a2dp) + { + playersView->ChangeView(PlayersView::MUISC_CONNECTING, PlayersView::MAIN_MUSICPLAYER_VIEW); + } + } + return; + } + static void PlayerMusic_TimerCallback(int data) + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(PlayerMusic_TimerCallbackProc, data)); + } + + void PlayersModel::PlayerMusic_StartTimer(uint32_t interval) + { + /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */ + if (g_timer != NULL) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersModel::StopWatch_StartTimer Timer already exists!!"); + return; + } + + /* --------------------------------- 2.创建定时器 -------------------------------- */ + g_timer = osTimerNew((osTimerFunc_t)PlayerMusic_TimerCallback, osTimerPeriodic, NULL, NULL); + // 检查定时器创建是否成功 + if (g_timer == NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayersModel::StopWatch_StartTimer Timer create failed!!"); + return; + } + + /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */ + int tick = osMs2Tick(interval); + + /* --------------------------------- 4.启动定时器 -------------------------------- */ + // g_timerStartTimestamp = GetCurrentTimestamp(); // 假设GetCurrentTimestamp()是获取当前时间戳的函数 + osStatus_t ret = osTimerStart(g_timer, tick); + /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 NULL -------------------- */ + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[StopWatch_StartTimer]osTimerDelete failed, ret = %lx!!", ret); + if (g_timer != NULL) + { + ret = osTimerDelete(g_timer); + } + g_timer = NULL; + return; + } + return; + } + + void PlayersModel::PlayerMusic_StopTimer(void) + { + // 检查定时器是否存在 + if (g_timer != NULL) + { + // 删除定时器并置为 NULL + osStatus_t ret = osTimerDelete(g_timer); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScanTimerCallback osTimerDelete failed, ret = %lx!!", ret); + } + g_timer = NULL; + g_PlayerTimes = 5; + } + } } #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 858364f59..27beed95a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersPresenter.cpp @@ -1474,16 +1474,6 @@ bool PlayersPresenter::OnClick(UIView &view, const ClickEvent &event) return false; } -void PlayersPresenter::UpdatePlayerView(bool musicSourceType, bool phoneMusicConnectStatus) -{ - PlayersView *playersView = PlayersView::GetInstance(); - if (playersView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playersView GetInstance fail"); - return; - } - playersView->UpdatePlayerView(musicSourceType,phoneMusicConnectStatus); -} - void PlayersPresenter::SetPlaybackProgress(int64_t value) { PlayersView *playersView = PlayersView::GetInstance(); 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 204cce835..f981c7dc8 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersView.cpp @@ -488,6 +488,12 @@ namespace OHOS delete musicPlayerBTConnectFailedView; musicPlayerBTConnectFailedView = nullptr; } + if (musicPlayerConnectingView != nullptr) + { + PlayersModel::GetInstance()->PlayerMusic_StopTimer(); + delete musicPlayerConnectingView; + musicPlayerConnectingView = nullptr; + } for (int i = MAIN_MUSICPLAYER_VIEW; i < MUSICPLAYERJUMPVIEWID_MAX; i++) { @@ -922,11 +928,15 @@ namespace OHOS } /*刷新播放器界面的组件状态*/ - void PlayersView::UpdatePlayerView(bool musicSourceType, bool phoneMusicConnectStatus) + void PlayersView::UpdatePlayerView(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UpdatePlayerView"); // 1.a2dp未连接,向手机发起a2dp连接 + bool phonebluetoothcon = SettingModel::GetInstance().GetPhoneConnectStatus(); // 获取手机连接状态 + bool a2dp = uapi_a2dp_snk_get_device_connect_state(); // 获取a2dp连接状态 + bool phoneMusicConnectStatus = phonebluetoothcon && a2dp; + bool musicSourceType = PlayersModel::GetInstance()->GetMusicSource(); // 2. ImageInfo *image; if (musicSourceType) @@ -989,9 +999,7 @@ namespace OHOS return false; } /* -------------------------------------------------------------------------- */ - bool phonebluetoothcon = SettingModel::GetInstance().GetPhoneConnectStatus(); // 获取手机连接状态 - bool a2dp = uapi_a2dp_snk_get_device_connect_state(); // 获取a2dp连接状态 - UpdatePlayerView(PlayersModel::GetInstance()->GetMusicSource(), phonebluetoothcon && a2dp); + UpdatePlayerView(); /* -------------------------------------------------------------------------- */ PlayersListGroup::GetInstance()->SetUpListCase(); @@ -1238,6 +1246,7 @@ namespace OHOS {PlayersView::MUSIC_DELETE_VIEW, &PlayersView::ChangeToMusicDeleteView}, {PlayersView::MUSIC_BLUETOOTH_DISCONN_VIEW, &PlayersView::ChangeToMusicBluetoothDisConnectView}, {PlayersView::MUSIC_BT_CONNECTFAILED_VIEW, &PlayersView::ChangeToMusicBluetoothConnectFailedView}, + {PlayersView::MUISC_CONNECTING, &PlayersView::ChangeToMusicConnectingView}, }; /*根据传入的 interface 值,在 ViewMapper 数组中查找匹配的 viewId*/ @@ -1278,10 +1287,37 @@ namespace OHOS return true; } + static const short PlayerDestroyMapper[] = { + PlayersView::MUISC_CONNECTING, + }; + /*删除临时视图*/ void PlayersView::DestroyTempView(int16_t hideView) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersView::DestroyTempView"); + int viewSize = sizeof(PlayerDestroyMapper) / sizeof(PlayerDestroyMapper[0]); + for (int i = 0; i < viewSize; i++) + { + if (hideView == PlayerDestroyMapper[i]) + { + Remove(group[hideView]); + group[hideView] = nullptr; + break; + } + } + switch (hideView) + { + case PlayersView::MUISC_CONNECTING: + PlayersModel::GetInstance()->PlayerMusic_StopTimer(); + if (musicPlayerConnectingView) + { + delete musicPlayerConnectingView; + musicPlayerConnectingView = nullptr; + } + break; + default: + break; + } } /*视图切换*/ @@ -1313,6 +1349,7 @@ namespace OHOS { Add(group[thisView]); } + UpdatePlayerView(); return true; } @@ -1372,7 +1409,7 @@ namespace OHOS group[thisView] = groupview; Add(group[thisView]); } - UpdateMusicListStatus();/*每次切换到音乐列表都将更新一次列表*/ + UpdateMusicListStatus(); /*每次切换到音乐列表都将更新一次列表*/ return true; } @@ -1448,27 +1485,28 @@ namespace OHOS return true; } - /*切换到蓝牙未连接视图*/ + /*切换到连接动画视图*/ bool PlayersView::ChangeToMusicConnectingView(int16_t thisView) { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayersView::ChangeToMusicBluetoothConnectFailedView"); - // if (group[thisView] == nullptr) - // { - // musicPlayerBTConnectFailedView = new MusicPlayerBTConnectFailedView(); - // if (musicPlayerBTConnectFailedView == nullptr) - // { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new playerListDelSongView fail"); - // return false; - // } - // UIViewGroup *groupview = musicPlayerBTConnectFailedView->CreateMusicPlayerBTConnectFailedView(); - // if (groupview == nullptr) - // { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new group[%d] fail", thisView); - // return false; - // } - // group[thisView] = groupview; - // Add(group[thisView]); - // } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayersView::ChangeToMusicConnectingView"); + if (group[thisView] == nullptr) + { + musicPlayerConnectingView = new AiVoiceConnectingView(); + if (musicPlayerConnectingView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new playerListDelSongView fail"); + return false; + } + UIViewGroup *groupview = musicPlayerConnectingView->CreateAiVoiceConnectingView(1); + if (groupview == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new group[%d] fail", thisView); + return false; + } + group[thisView] = groupview; + Add(group[thisView]); + } + PlayersModel::GetInstance()->PlayerMusic_StartTimer(); return true; } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingModel.cpp index f8fc69b0c..2dfd7d38d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingModel.cpp @@ -2,13 +2,14 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-02-18 09:09:13 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-22 10:51:12 + * @LastEditTime: 2024-08-20 17:42:37 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingModel.cpp */ #include "settings/include/SettingModel.h" #include "main/include/PullUpDownView.h" #include "ui_resource_string.h" #include "classicbluetooth/include/BluetoothServiceOptionsView.h" +#include "player/include/PlayersView.h" namespace OHOS { SettingModel::SettingModel() {} @@ -99,5 +100,9 @@ namespace OHOS { BluetoothServiceOptionsView::GetInstance()->Button_UPdata(); } + if(PlayersView::GetInstance()) + { + PlayersView::GetInstance()->UpdatePlayerView(); + } } } -- 2.17.1