Class VideoProgressTracker
-
- All Implemented Interfaces:
public final class VideoProgressTrackerVideoProgressTracker monitors the playback progress of a video on a MediaPlayer instance. It emits events for video progress updates, including quartile milestones (25%, 50%, 75%) and completion. This class uses coroutines to periodically check the video's current position and emit relevant VideoEvents to the provided progressEvents flow.
-
-
Constructor Summary
Constructors Constructor Description VideoProgressTracker(MediaPlayer mediaPlayer, CoroutineScope coroutineScope, Long progressPollingInterval, MutableSharedFlow<VideoEvent> progressEvents)
-
Method Summary
Modifier and Type Method Description final UnitstartTracking()Starts tracking the progress of the video for the given mediaPlayer. final UnitresetTracking()Resets the video progress tracking by stopping and starting the tracking again. final UnitstopTracking()Stops tracking the progress of the video for the given mediaPlayer. -
-
Constructor Detail
-
VideoProgressTracker
VideoProgressTracker(MediaPlayer mediaPlayer, CoroutineScope coroutineScope, Long progressPollingInterval, MutableSharedFlow<VideoEvent> progressEvents)
- Parameters:
mediaPlayer- The MediaPlayer instance to monitor.coroutineScope- The CoroutineScope to use for launching coroutines.progressPollingInterval- The interval in milliseconds between each progress check.progressEvents- The MutableSharedFlow to emit progress events to.
-
-
Method Detail
-
startTracking
final Unit startTracking()
Starts tracking the progress of the video for the given mediaPlayer.
This method begins periodic polling of video progress and sets up completion listener. If tracking is already started, subsequent calls are ignored.
-
resetTracking
final Unit resetTracking()
Resets the video progress tracking by stopping and starting the tracking again.
This method is useful when the video restarts or when you need to reset the quartile tracking state back to the beginning.
-
stopTracking
final Unit stopTracking()
Stops tracking the progress of the video for the given mediaPlayer.
This method cancels the tracking coroutine, removes completion listener, and resets the started flag. Safe to call multiple times.
-
-
-
-