feat: 移除视频循环播放,添加播放完成监听

- 将 setLooping 改为 false,播放完成后不再循环
- 在 onCompletion 回调中添加 isPrepared = false 状态重置
- 更新 VideoPlayerCallback 接口注释,说明 onCompletion() 现在会被触发
- 优化日志输出,将 "Video completed" 改为 "Video playback completed"

这些修改使得视频播放完成后能够触发回调,为自动切换下一个视频做准备。

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
hughhuangandClaude Sonnet 4.5 committed 2026-01-31 17:32:24 +08:00
1 parent 29af9d367e
commit 400029916c
1 file changed
+6 -5
@@ -27,9 +27,9 @@ public class VideoPlayer {
private FileLogger fileLogger;
public interface VideoPlayerCallback {
void onPrepared();
void onError(String error);
void onCompletion();
void onPrepared(); // 视频准备完成
void onError(String error); // 播放出错
void onCompletion(); // 播放完成(现在会触发,因为不再循环)
}
public void setSurface(Surface surface) {
@@ -68,7 +68,7 @@ public class VideoPlayer {
throw e;
}
mediaPlayer.setLooping(true);
mediaPlayer.setLooping(false); // 改为 false,播放完成后不循环
mediaPlayer.setVolume(volume, volume);
mediaPlayer.setOnPreparedListener(mp -> {
@@ -120,7 +120,8 @@ public class VideoPlayer {
fileLogger.warn(TAG, "Ignoring onCompletion from stale MediaPlayer");
return;
}
fileLogger.log(TAG, "Video completed");
fileLogger.log(TAG, "Video playback completed");
isPrepared = false; // 标记为未准备状态
if (callback != null) {
callback.onCompletion();
}