fix: 修复视频播放完成后不切换和画面残留问题
- 添加 videoCompleted 标志,用于触发视频完成后的媒体切换 - 在 drawWallpaper() 中检查 videoCompleted 标志并切换到下一个媒体 - 在 stopVideo() 中调用 clearSurface() 清除视频最后画面 - 修复了视频播放完成后不自动切换的问题 - 修复了从视频切换到图片时画面残留的问题 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
432e596511
commit
8ebbb4a2d4
1 file changed
+11
-3
@@ -124,6 +124,7 @@ public class AutoWallpaperService extends WallpaperService {
|
||||
private volatile boolean isLoadingWallpaper = false; // 防止重复加载
|
||||
private boolean isCharging = true; // Default to charging to avoid pausing initially
|
||||
private boolean changeOnReturn = false; // 标志:是否因返回桌面而需要更换壁纸
|
||||
private boolean videoCompleted = false; // 标志:视频播放完成,需要切换到下一个媒体
|
||||
|
||||
// 双击检测相关
|
||||
private long lastTapTime = 0;
|
||||
@@ -201,7 +202,8 @@ public class AutoWallpaperService extends WallpaperService {
|
||||
return;
|
||||
}
|
||||
|
||||
// 重置状态标志(只有在确定要执行切换时才重置)
|
||||
// 设置视频完成标志,触发切换到下一个媒体
|
||||
videoCompleted = true;
|
||||
isLoadingWallpaper = false;
|
||||
isPlayingVideo = false;
|
||||
|
||||
@@ -211,8 +213,8 @@ public class AutoWallpaperService extends WallpaperService {
|
||||
drawWallpaper();
|
||||
} catch (Exception e) {
|
||||
fileLogger.error(TAG, "Error switching to next media after video completion", e);
|
||||
videoCompleted = false;
|
||||
isLoadingWallpaper = false;
|
||||
isPlayingVideo = false; // 确保状态一致
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -362,7 +364,7 @@ public class AutoWallpaperService extends WallpaperService {
|
||||
boolean shouldChange = false;
|
||||
|
||||
String statusMsg = "drawWallpaper: forceChangeNext=" + forceChangeNext + ", scheduledNext=" + scheduledNext +
|
||||
", changeOnReturn=" + changeOnReturn;
|
||||
", changeOnReturn=" + changeOnReturn + ", videoCompleted=" + videoCompleted;
|
||||
Log.i(TAG, statusMsg);
|
||||
fileLogger.log(TAG, statusMsg);
|
||||
|
||||
@@ -375,6 +377,9 @@ public class AutoWallpaperService extends WallpaperService {
|
||||
} else if (changeOnReturn) {
|
||||
shouldChange = true;
|
||||
fileLogger.log(TAG, "Change on return to home");
|
||||
} else if (videoCompleted) {
|
||||
shouldChange = true;
|
||||
fileLogger.log(TAG, "Video playback completed, switching to next media");
|
||||
}
|
||||
|
||||
// 重置标志
|
||||
@@ -382,6 +387,7 @@ public class AutoWallpaperService extends WallpaperService {
|
||||
forceChangeNext = false;
|
||||
scheduledNext = false;
|
||||
changeOnReturn = false; // 重置返回桌面标志
|
||||
videoCompleted = false; // 重置视频完成标志
|
||||
|
||||
// 如果不需要更换且有缓存,保持当前媒体
|
||||
if (!needChange && currentMedia != null) {
|
||||
@@ -839,6 +845,8 @@ public class AutoWallpaperService extends WallpaperService {
|
||||
if (isPlayingVideo) {
|
||||
videoPlayer.release();
|
||||
isPlayingVideo = false;
|
||||
// 清除视频画面,避免保留最后帧
|
||||
clearSurface();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user