From 2b6f8145df5b6f7975f74354a4a1c20472b9b41f Mon Sep 17 00:00:00 2001 From: hugh <1012760428@qq.com> Date: Sat, 31 Jan 2026 20:00:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20onCompletion=20?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E7=8A=B6=E6=80=81=E9=87=8D=E7=BD=AE=E6=97=B6?= =?UTF-8?q?=E6=9C=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将状态重置移到可见性检查之后,避免竞态条件 - 在异常处理中同时重置 isPlayingVideo 状态 - 确保状态标志在所有路径上都正确重置 Co-Authored-By: Claude Sonnet 4.5 --- .../hugh/bz/gk2/wallpaper/AutoWallpaperService.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/cn/hugh/bz/gk2/wallpaper/AutoWallpaperService.java b/app/src/main/java/cn/hugh/bz/gk2/wallpaper/AutoWallpaperService.java index 4d322a2..970a77e 100644 --- a/app/src/main/java/cn/hugh/bz/gk2/wallpaper/AutoWallpaperService.java +++ b/app/src/main/java/cn/hugh/bz/gk2/wallpaper/AutoWallpaperService.java @@ -186,16 +186,19 @@ public class AutoWallpaperService extends WallpaperService { public void onCompletion() { fileLogger.log(TAG, "Video completed, switching to next media"); - // 重置状态标志 - isLoadingWallpaper = false; - isPlayingVideo = false; - // 检查 Surface 是否仍然有效 if (!visible) { fileLogger.log(TAG, "Surface not visible, skipping auto-switch"); + // 在这里重置状态,因为确实不需要加载了 + isLoadingWallpaper = false; + isPlayingVideo = false; return; } + // 重置状态标志(只有在确定要执行切换时才重置) + isLoadingWallpaper = false; + isPlayingVideo = false; + // 触发切换到下一个媒体 handler.post(() -> { try { @@ -203,6 +206,7 @@ public class AutoWallpaperService extends WallpaperService { } catch (Exception e) { fileLogger.error(TAG, "Error switching to next media after video completion", e); isLoadingWallpaper = false; + isPlayingVideo = false; // 确保状态一致 } }); }