fix: 修复 onCompletion 中的状态重置时机问题
- 将状态重置移到可见性检查之后,避免竞态条件 - 在异常处理中同时重置 isPlayingVideo 状态 - 确保状态标志在所有路径上都正确重置 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c0cb8e43d2
commit
2b6f8145df
1 file changed
+8
-4
@@ -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; // 确保状态一致
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user