SeekCalculator.java

Overview

`SeekCalculator` is a utility class designed to support dynamic seek interval calculations during media playback. Its primary role is to compute the appropriate seek jump length (in milliseconds) based on the duration for which the user has been seeking (e.g., holding fast-forward or rewind buttons) and the frequency of seek events. This adaptive behavior enables a smooth and intuitive seeking experience by progressively increasing seek intervals the longer the user continuously seeks, while also throttling seek updates to avoid overwhelming the playback engine.

This class is part of the media playback utilities and interacts primarily with user input handling components and playback controllers to determine how far the video should jump forward or backward during seeking operations.


Class: SeekCalculator

Package

package com.tubitv.media.utilities;

Constants

Name

Type

Value

Description

`FORWARD_DIRECTION`

int

1

Indicates forward seeking direction

`REWIND_DIRECTION`

int

-1

Indicates rewind seeking direction

`FAST_SEEK_INTERVAL`

long

15,000 ms (15 s)

Preset fast seek interval (not used directly in current logic)

`SEEK_INTERVAL_SHORT`

long

8,000 ms (8 s)

Seek interval for short duration seeking

`SEEK_INTERVAL_RERGUAR`

long

64,000 ms (64 s)

Seek interval for medium duration seeking

`SEEK_INTERVAL_LONG`

long

256,000 ms (256 s)

Seek interval for long duration seeking

`FIRST_SPEED_INTERVAL`

long

1,000 ms (1 s)

Threshold for starting seek intervals

`SECOND_SPEED_INTERVAL`

long

2,000 ms (2 s)

Threshold for medium seek intervals

`THIRD_SPEED_INTERVAL`

long

6,000 ms (6 s)

Threshold for long seek intervals

`SEEK_FREQUENCY`

int

250 ms (1000 / 4)

Minimum interval between consecutive seeks (4 per second)

Fields

Name

Type

Description

`sLastUpdateTime`

Long

Stores the timestamp of the last seek update; initialized on first seek event


Methods

public static long getSeekRate(long startTime, long currentTime)

Calculates the current seek interval based on the total elapsed seek duration and enforces a maximum frequency of seek events.


private static long getCurrentSeekRate(long startTime, long currentTime)

Determines the seek interval based on the elapsed time since the seek started.


Important Implementation Details


Interaction with Other Components


Usage Example

long seekStartTime = System.currentTimeMillis();
int direction = SeekCalculator.FORWARD_DIRECTION; // or REWIND_DIRECTION

// Called repeatedly as user continues to seek
while(seeking) {
    long currentTime = System.currentTimeMillis();
    long seekInterval = SeekCalculator.getSeekRate(seekStartTime, currentTime);

    if (seekInterval > 0) {
        long newPosition = currentPlaybackPosition + (seekInterval * direction);
        player.seekTo(newPosition);
    }

    // Sleep or wait for next input event...
}

Mermaid Class Diagram

classDiagram
    class SeekCalculator {
        <<utility>>
        - static final int FORWARD_DIRECTION = 1
        - static final int REWIND_DIRECTION = -1
        - static final long FAST_SEEK_INTERVAL = 15000
        - static final long SEEK_INTERVAL_SHORT = 8000
        - static final long SEEK_INTERVAL_RERGUAR = 64000
        - static final long SEEK_INTERVAL_LONG = 256000
        - static final long FIRST_SPEED_INTERVAL = 1000
        - static final long SECOND_SPEED_INTERVAL = 2000
        - static final long THIRD_SPEED_INTERVAL = 6000
        - static final int SEEK_FREQUENCY = 250
        - static Long sLastUpdateTime
        + static long getSeekRate(long startTime, long currentTime)
        - static long getCurrentSeekRate(long startTime, long currentTime)
    }

Summary

`SeekCalculator` enables adaptive, frequency-controlled seek intervals that improve user experience during fast-forward and rewind operations in media playback. By escalating seek intervals over time and throttling update frequency, it balances responsiveness with smooth navigation, making it a crucial utility in the playback control subsystem.