Class VideoProgressTracker

  • All Implemented Interfaces:

    
    public final class VideoProgressTracker
    
                        

    VideoProgressTracker 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.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Unit startTracking() Starts tracking the progress of the video for the given mediaPlayer.
      final Unit resetTracking() Resets the video progress tracking by stopping and starting the tracking again.
      final Unit stopTracking() Stops tracking the progress of the video for the given mediaPlayer.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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.