fix: 增强视频完成回调的错误处理

- 添加 Surface 可见性检查
- 添加异常捕获和日志记录
- 确保状态标志正确重置

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
hughhuangandClaude Sonnet 4.5 committed 2026-01-31 19:55:04 +08:00
1 parent 3d1916de62
commit c0cb8e43d2
1 file changed
+16 -3
@@ -185,12 +185,25 @@ public class AutoWallpaperService extends WallpaperService {
@Override
public void onCompletion() {
fileLogger.log(TAG, "Video completed, switching to next media");
isLoadingWallpaper = false; // 允许新的加载请求
isPlayingVideo = false; // 标记当前不在播放视频
// 触发切换到下一个媒体(不设置 forceChangeNext,使用正常流程)
// 重置状态标志
isLoadingWallpaper = false;
isPlayingVideo = false;
// 检查 Surface 是否仍然有效
if (!visible) {
fileLogger.log(TAG, "Surface not visible, skipping auto-switch");
return;
}
// 触发切换到下一个媒体
handler.post(() -> {
try {
drawWallpaper();
} catch (Exception e) {
fileLogger.error(TAG, "Error switching to next media after video completion", e);
isLoadingWallpaper = false;
}
});
}
});