优化亮屏继续播放视频逻辑
authorxue <2144439972@qq.com>
Sat, 13 Dec 2025 06:54:57 +0000 (14:54 +0800)
committerxue <2144439972@qq.com>
Sat, 13 Dec 2025 06:54:57 +0000 (14:54 +0800)
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdMainView.cpp

index d9e6cc8..9c669fe 100644 (file)
@@ -74,63 +74,59 @@ namespace OHOS
         if (status == SCREEN_STATUS_OFF)
         {
             // 立即执行视频暂停操作
-            
-                if(g_videoPlay->isPlayed_)
-                {
-                    g_videoPlay->PauseVideoPlay();
-                }
-            
-            // 检测是否在联网成功到获取时间线完成这个阶段
-            // ThunderBirdModel *model = ThunderBirdModel::GetInstance();
-            // bool hasNetwork = (model != nullptr) ? model->HasNetwork() : false;
-            // bool isBound = (model != nullptr) ? model->getbind_status() : false;
-            
-            // 无论是否绑定,都需要联网才能休眠
-            // if (!hasNetwork) {
-            //     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenStatusNotify: 未联网,不休眠");
-            //     return;
-            // }
-            
-            // 如果已绑定:需要等待时间线获取完成才能休眠
-            // 如果未绑定:联网成功就可以休眠,不需要等待时间线
-            // if (isBound && !g_timelineReceived) {
-            //     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenStatusNotify: 已绑定且联网成功但时间线未获取,不休眠");
-            //     return;
-            // }
-            
-            // 未绑定且联网成功,或已绑定且时间线已获取,允许休眠
-            // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenStatusNotify: 执行休眠 (isBound=%d, hasNetwork=%d, timelineReceived=%d)", 
-            //              isBound, hasNetwork, g_timelineReceived);
-            // 立即执行休眠操作
-            // ln_ws_enter_sleep();
+            if(g_videoPlay->isPlayed_)
+            {
+                g_videoPlay->PauseVideoPlay();
+            }
+            // 保存播放状态,用于亮屏时恢复
+            g_lastPlayed = temp;
+
         }
         else if (status == SCREEN_STATUS_ON)
         {
-            if (g_lastPlayed && g_videoPlay->isPause_)
+            // 亮屏时恢复视频播放
+            // 检查视频播放器是否已进入且之前正在播放
+            if (g_videoPlay->isEntered_)
             {
-                g_videoPlay->ResumeVideoPlay();
+                if (g_lastPlayed && g_videoPlay->isPause_)
+                {
+                    // 如果之前正在播放且现在暂停,恢复播放
+                    g_videoPlay->ResumeVideoPlay();
+                    WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ScreenStatusNotify: Resumed video playback on screen on");
+                }
+                else if (g_lastPlayed && !g_videoPlay->isPlayed_)
+                {
+                    // 如果之前正在播放但现在未播放,重新启动播放
+                    g_videoPlay->StartVideoPlay();
+                    WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ScreenStatusNotify: Restarted video playback on screen on");
+                }
             }
+            else
+            {
+                // 如果视频播放器未进入,可能需要重新初始化
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenStatusNotify: Video player not entered, may need reinit");
+            }
+            
             // 亮屏时,如果当前在状态展示界面,刷新字幕显示(重置跑马灯偏移)
-                int16_t currentView = ThunderBirdMainView::GetInstance()->GetCurrentView();
-                int16_t currentSubView = ThunderBirdMainView::GetInstance()->GetCurrentSubView();
-                if (currentView == THUNDERBIRD_DIALOGUEVIEW && 
-                    currentSubView == ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_STATUS_SHOW) {
-                    // 刷新字幕显示,重置跑马灯偏移
-                    ThunderBirdDialogueView *dialogueView = ThunderBirdDialogueView::GetInstance();
-                    if (dialogueView != nullptr) {
-                        ThunderBirdModel *model = ThunderBirdModel::GetInstance();
-                        if (model != nullptr) {
-                            std::string currentStatusText = model->GetCurrentStatusText();
-                            if (currentStatusText.empty()) {
-                                currentStatusText = "发呆中...     ";
-                            }
-                            dialogueView->UpdateDialogueText(currentStatusText.c_str());
+            int16_t currentView = ThunderBirdMainView::GetInstance()->GetCurrentView();
+            int16_t currentSubView = ThunderBirdMainView::GetInstance()->GetCurrentSubView();
+            if (currentView == THUNDERBIRD_DIALOGUEVIEW && 
+                currentSubView == ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_STATUS_SHOW) {
+                // 刷新字幕显示,重置跑马灯偏移
+                ThunderBirdDialogueView *dialogueView = ThunderBirdDialogueView::GetInstance();
+                if (dialogueView != nullptr) {
+                    ThunderBirdModel *model = ThunderBirdModel::GetInstance();
+                    if (model != nullptr) {
+                        std::string currentStatusText = model->GetCurrentStatusText();
+                        if (currentStatusText.empty()) {
+                            currentStatusText = "发呆中...     ";
                         }
+                        dialogueView->UpdateDialogueText(currentStatusText.c_str());
                     }
                 }
+            }
             // ln_ws_exit_sleep();
         }
-        g_lastPlayed = temp;
     }
     
     static ThunderBirdMainView *g_pThunderBirdMainView{nullptr};