// 时间线是否已获取标志
static bool g_timelineReceived = false; // 时间线是否已获取
+ // 正在切换视频标志,用于防止在切换视频时被屏幕状态通知暂停
+ static bool g_isSwitchingVideo = false;
+
static void ScreenStatusNotify(ScreenStatus status)
{
if (g_videoPlay == nullptr)
return;
}
+ // 如果正在切换视频,不执行暂停操作
+ if (g_isSwitchingVideo)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ScreenStatusNotify: 正在切换视频,忽略屏幕状态变化");
+ return;
+ }
+
bool temp = g_videoPlay->isPlayed_;
if (status == SCREEN_STATUS_OFF)
{
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdMainView::SwitchVideo: Already playing the same video, skipping: %s", uri);
return true; // 返回true表示"成功",因为不需要切换
}
+
+ // 设置切换视频标志,防止屏幕状态通知暂停播放
+ g_isSwitchingVideo = true;
+
+ // 检查屏幕状态,如果屏幕关闭,先亮屏并等待
+ int screenState = uapi_get_screen_state();
+ if (screenState != 0) {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdMainView::SwitchVideo: Screen is off (state=%d), turning on screen", screenState);
+ uapi_set_screen_on_api();
+ // 等待屏幕亮起(最多等待500ms,每次检查50ms)
+ int waitCount = 0;
+ const int maxWaitCount = 10; // 10 * 50ms = 500ms
+ while (waitCount < maxWaitCount) {
+ usleep(50000); // 等待50ms (50000微秒)
+ screenState = uapi_get_screen_state();
+ if (screenState == 0) {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdMainView::SwitchVideo: Screen is now on after %d ms", waitCount * 50);
+ break;
+ }
+ waitCount++;
+ }
+ if (screenState != 0) {
+ WEARABLE_LOGW(WEARABLE_LOG_MODULE_APP, "ThunderBirdMainView::SwitchVideo: Screen still off after waiting, proceeding anyway");
+ }
+ }
+
// 停止并销毁旧播放器
if (videoPlay_ != nullptr)
{
if (surface == nullptr)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdMainView::SwitchVideo: Failed to get surface from surfaceView_");
+ g_isSwitchingVideo = false; // 清除标志
return false;
}
if (videoPlay_ == nullptr)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdMainView::SwitchVideo: Failed to create MediaVideoPlay");
+ g_isSwitchingVideo = false; // 清除标志
return false;
}
g_videoPlay = videoPlay_;
if (ret != 0)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdMainView::SwitchVideo: Failed to start video play, ret=%d", ret);
+ g_isSwitchingVideo = false; // 清除标志
return false;
}
// 更新当前播放的视频路径
currentVideoPath_ = std::string(uri);
+ // 清除切换视频标志
+ g_isSwitchingVideo = false;
+
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdMainView::SwitchVideo: Successfully switched to video: %s", uri);
return true;
}