From 3df9d840aea755c3964dbecc722021faddb652c6 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Tue, 3 Sep 2024 16:18:41 +0800 Subject: [PATCH] =?utf8?q?=E6=89=8B=E6=9C=BA=E9=9F=B3=E4=B9=90=E5=92=8C?= =?utf8?q?=E6=89=8B=E8=A1=A8=E9=9F=B3=E4=B9=90=E5=88=87=E6=8D=A2=E6=B7=BB?= =?utf8?q?=E5=8A=A0=E5=8A=A8=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../player/src/MusicPlayerSourceView.cpp | 64 ++++++++++++------- .../nativeui/player/src/PlayersModel.cpp | 32 +++++++--- .../nativeui/player/src/PlayersView.cpp | 6 +- 3 files changed, 71 insertions(+), 31 deletions(-) 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 1bef02af6..3935378da 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/src/MusicPlayerSourceView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/player/src/MusicPlayerSourceView.cpp @@ -61,24 +61,31 @@ namespace OHOS if (button == phoneLableButton) // 若点击的是手机音乐按钮 { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnClick phoneLableButton"); - PlayersModel::GetInstance()->SetMusicSource(true); - UpdateBluetoothHeadSetViewIsVisible(); + if (!PlayersModel::GetInstance()->GetMusicSource()) // 切换到手机音乐 + { + PlayersModel::GetInstance()->SetMusicSource(true); + UpdateBluetoothHeadSetViewIsVisible(); - // 1.a2dp未连接,向手机发起a2dp连接 - // 如果蓝牙没连接直接是跳转到蓝牙连接失败视图,连接了就有一个主动去连手机的a2dp过程,5秒超市 + // 1.a2dp未连接,向手机发起a2dp连接 + // 如果蓝牙没连接直接是跳转到蓝牙连接失败视图,连接了就有一个主动去连手机的a2dp过程,5秒超市 - if (!phonebluetoothcon) - { - playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MUSIC_BLUETOOTH_DISCONN_VIEW); - } - else if (phonebluetoothcon && !a2dp) // 如果手机蓝牙已连接但手表与手机的a2dp未连接手表主动去连接a2dp - { - /* -------------------------------------------------------------------------- */ - uapi_a2dp_snk_connect(); // 切换通道主动连接atdp - /* -------------------------------------------------------------------------- */ - playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MUISC_CONNECTING); + if (!phonebluetoothcon) + { + playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MUSIC_BLUETOOTH_DISCONN_VIEW); + } + else if (phonebluetoothcon && !a2dp) // 如果手机蓝牙已连接但手表与手机的a2dp未连接手表主动去连接a2dp + { + /* -------------------------------------------------------------------------- */ + uapi_a2dp_snk_connect(); // 切换通道主动连接atdp + /* -------------------------------------------------------------------------- */ + playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MUISC_CONNECTING); + } + else if (phonebluetoothcon && a2dp) + { + playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MAIN_MUSICPLAYER_VIEW); + } } - else if (phonebluetoothcon && a2dp) + else // 如果已经选择了手机音乐,再次点击就回到 “音乐播放器主视图” { playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MAIN_MUSICPLAYER_VIEW); } @@ -86,14 +93,22 @@ namespace OHOS else if (button == watchLableButton) // 若点击的是手表音乐按钮 { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnClick watchLableButton"); - PlayersModel::GetInstance()->SetMusicSource(false); - UpdateBluetoothHeadSetViewIsVisible(); - /* -------------------------------------------------------------------------- */ - if (a2dp) + if (PlayersModel::GetInstance()->GetMusicSource()) // 切换到手表音乐 { - uapi_a2dp_snk_disconnect(); // 切换通道主动断开atdp + PlayersModel::GetInstance()->SetMusicSource(false); + UpdateBluetoothHeadSetViewIsVisible(); + /* -------------------------------------------------------------------------- */ + if (a2dp) + { + uapi_a2dp_snk_disconnect(); // 切换通道主动断开atdp + } + /* -------------------------------------------------------------------------- */ + playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MUISC_CONNECTING); + } + else // 如果已经选择了手表音乐,再次点击就回到 “音乐播放器主视图” + { + playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MAIN_MUSICPLAYER_VIEW); } - /* -------------------------------------------------------------------------- */ } else if (button == bluetoothHeadsetLableButton) { @@ -430,6 +445,10 @@ namespace OHOS scrollView->SetPosition(0, 0, 466, 466); scrollView->SetScrollBlankSize(75); scrollView->SetReboundSize(35); + scrollView->SetThrowDrag(true); + scrollView->SetMaxScrollDistance(1000); + scrollView->SetDragACCLevel(5); + scrollView->SetSwipeACCLevel(800); /*设置手指抬起屏幕后的补偿距离。*/ scrollView->SetDirection(UIScrollView::VERTICAL); group->Add(scrollView); @@ -459,7 +478,7 @@ namespace OHOS void MusicPlayerSourceView::UpdateBluetoothHeadSetViewIsVisible(void) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerSourceView::CreateMusicPlayerSourceViewImage"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerSourceView::UpdateBluetoothHeadSetViewIsVisible"); bool value = PlayersModel::GetInstance()->GetMusicSource(); if (bluetoothHeadsetLabel && bluetoothHeadsetImage && bluetoothHeadsetLableButton && bluetoothHeadsetConnectState) { @@ -484,6 +503,7 @@ namespace OHOS scrollView->Invalidate(); } + /*更新蓝牙耳机连接状态*/ void MusicPlayerSourceView::UpdateBluetoothHeadsetConnectLabel(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerSourceView::UpdateBluetoothHeadsetConnectLabel"); 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 41cffdbbb..66bf5feda 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp @@ -819,16 +819,32 @@ bool PlayersModel::GetCurrentMusicIsPlaying(void) 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); + bool type = PlayersModel::GetInstance()->GetMusicSource(); + if(type) { + if(g_PlayerTimes < 0) /*5秒超时*/ + { + playersView->ChangeView(PlayersView::MUISC_CONNECTING, PlayersView::MUSIC_BT_CONNECTFAILED_VIEW); + } + else + { + if(g_PlayerTimes < 2) /*3秒切换时间*/ + { + bool a2dp = uapi_a2dp_snk_get_device_connect_state();// 获取a2dp连接状态 + if(a2dp) + { + playersView->ChangeView(PlayersView::MUISC_CONNECTING, PlayersView::MUSIC_SOURCE_VIEW); + } + } + } } - else - { - bool a2dp = uapi_a2dp_snk_get_device_connect_state();// 获取a2dp连接状态 - if(a2dp) + else { + if(g_PlayerTimes < 2) /*3秒切换时间*/ { - playersView->ChangeView(PlayersView::MUISC_CONNECTING, PlayersView::MAIN_MUSICPLAYER_VIEW); + bool a2dp = uapi_a2dp_snk_get_device_connect_state();// 获取a2dp连接状态 + if(!a2dp) + { + playersView->ChangeView(PlayersView::MUISC_CONNECTING, PlayersView::MUSIC_SOURCE_VIEW); + } } } 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 f71306099..5c1fe6893 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersView.cpp @@ -855,7 +855,7 @@ namespace OHOS soundButton->SetTouchable(touchableState); playerModelButton->SetTouchable(touchableState); // 如果音乐来源为手机音乐,播放顺序按钮就不可用 /* -------------------------------------------------------------------------- */ - if (musicSourceType) //如果切換到手机音乐,且当前在放歌,就停止音乐 + if (musicSourceType) // 如果切換到手机音乐,且当前在放歌,就停止音乐 { /*暂停音乐*/ uint8_t state = GetPlayerButtonState(); @@ -987,6 +987,10 @@ namespace OHOS MusicSourceLabelSetText(STR_WATCH_MUSIC); /*手表音乐*/ SetMusicPlayerButtonIsTouchable(false); } + if (musicPlayerSourceView) + { + musicPlayerSourceView->UpdateBluetoothHeadSetViewIsVisible(); + } WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UpdatePlayerView over!!"); } -- 2.17.1