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:
1 parent
29af9d367e
commit
400029916c
1 file changed
+6
-5
@@ -27,9 +27,9 @@ public class VideoPlayer {
|
|||||||
private FileLogger fileLogger;
|
private FileLogger fileLogger;
|
||||||
|
|
||||||
public interface VideoPlayerCallback {
|
public interface VideoPlayerCallback {
|
||||||
void onPrepared();
|
void onPrepared(); // 视频准备完成
|
||||||
void onError(String error);
|
void onError(String error); // 播放出错
|
||||||
void onCompletion();
|
void onCompletion(); // 播放完成(现在会触发,因为不再循环)
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSurface(Surface surface) {
|
public void setSurface(Surface surface) {
|
||||||
@@ -68,7 +68,7 @@ public class VideoPlayer {
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
mediaPlayer.setLooping(true);
|
mediaPlayer.setLooping(false); // 改为 false,播放完成后不循环
|
||||||
mediaPlayer.setVolume(volume, volume);
|
mediaPlayer.setVolume(volume, volume);
|
||||||
|
|
||||||
mediaPlayer.setOnPreparedListener(mp -> {
|
mediaPlayer.setOnPreparedListener(mp -> {
|
||||||
@@ -120,7 +120,8 @@ public class VideoPlayer {
|
|||||||
fileLogger.warn(TAG, "Ignoring onCompletion from stale MediaPlayer");
|
fileLogger.warn(TAG, "Ignoring onCompletion from stale MediaPlayer");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fileLogger.log(TAG, "Video completed");
|
fileLogger.log(TAG, "Video playback completed");
|
||||||
|
isPrepared = false; // 标记为未准备状态
|
||||||
if (callback != null) {
|
if (callback != null) {
|
||||||
callback.onCompletion();
|
callback.onCompletion();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user