public interface

TimeBar

 androidx.media3.ui.TimeBar

Subclasses:

DefaultTimeBar

Gradle dependencies

compile group: 'androidx.media3', name: 'media3-ui', version: '1.5.0-alpha01'

  • groupId: androidx.media3
  • artifactId: media3-ui
  • version: 1.5.0-alpha01

Artifact androidx.media3:media3-ui:1.5.0-alpha01 it located at Google repository (https://maven.google.com/)

Overview

Interface for time bar views that can display a playback position, buffered position, duration and ad markers, and that have a listener for scrubbing (seeking) events.

Summary

Methods
public voidaddListener(TimeBar.OnScrubListener listener)

Adds a listener for scrubbing events.

public longgetPreferredUpdateDelay()

Returns the preferred delay in milliseconds of media time after which the time bar position should be updated.

public voidremoveListener(TimeBar.OnScrubListener listener)

Removes a listener for scrubbing events.

public voidsetAdGroupTimesMs(long[] adGroupTimesMs[], boolean[] playedAdGroups[], int adGroupCount)

Sets the times of ad groups and whether each ad group has been played.

public voidsetBufferedPosition(long bufferedPosition)

Sets the buffered position.

public voidsetDuration(long duration)

Sets the duration.

public voidsetEnabled(boolean enabled)

public voidsetKeyCountIncrement(int count)

Sets the position increment for key presses and accessibility actions, as a number of increments that divide the duration of the media.

public voidsetKeyTimeIncrement(long time)

Sets the position increment for key presses and accessibility actions, in milliseconds.

public voidsetPosition(long position)

Sets the current position.

Methods

public void addListener(TimeBar.OnScrubListener listener)

Adds a listener for scrubbing events.

Parameters:

listener: The listener to add.

public void removeListener(TimeBar.OnScrubListener listener)

Removes a listener for scrubbing events.

Parameters:

listener: The listener to remove.

public void setEnabled(boolean enabled)

See also: View

public void setKeyTimeIncrement(long time)

Sets the position increment for key presses and accessibility actions, in milliseconds.

Clears any increment specified in a preceding call to TimeBar.setKeyCountIncrement(int).

Parameters:

time: The time increment, in milliseconds.

public void setKeyCountIncrement(int count)

Sets the position increment for key presses and accessibility actions, as a number of increments that divide the duration of the media. For example, passing 20 will cause key presses to increment/decrement the position by 1/20th of the duration (if known).

Clears any increment specified in a preceding call to TimeBar.setKeyTimeIncrement(long).

Parameters:

count: The number of increments that divide the duration of the media.

public void setPosition(long position)

Sets the current position.

Parameters:

position: The current position to show, in milliseconds.

public void setBufferedPosition(long bufferedPosition)

Sets the buffered position.

Parameters:

bufferedPosition: The current buffered position to show, in milliseconds.

public void setDuration(long duration)

Sets the duration.

Parameters:

duration: The duration to show, in milliseconds.

public long getPreferredUpdateDelay()

Returns the preferred delay in milliseconds of media time after which the time bar position should be updated.

Returns:

Preferred delay, in milliseconds of media time.

public void setAdGroupTimesMs(long[] adGroupTimesMs[], boolean[] playedAdGroups[], int adGroupCount)

Sets the times of ad groups and whether each ad group has been played.

Parameters:

adGroupTimesMs: An array where the first adGroupCount elements are the times of ad groups in milliseconds. May be null if there are no ad groups.
playedAdGroups: An array where the first adGroupCount elements indicate whether the corresponding ad groups have been played. May be null if there are no ad groups.
adGroupCount: The number of ad groups.

Source

/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package androidx.media3.ui;

import android.view.View;
import androidx.annotation.Nullable;
import androidx.media3.common.util.UnstableApi;

/**
 * Interface for time bar views that can display a playback position, buffered position, duration
 * and ad markers, and that have a listener for scrubbing (seeking) events.
 */
@UnstableApi
public interface TimeBar {

  /**
   * Adds a listener for scrubbing events.
   *
   * @param listener The listener to add.
   */
  void addListener(OnScrubListener listener);

  /**
   * Removes a listener for scrubbing events.
   *
   * @param listener The listener to remove.
   */
  void removeListener(OnScrubListener listener);

  /**
   * @see View#isEnabled()
   */
  void setEnabled(boolean enabled);

  /**
   * Sets the position increment for key presses and accessibility actions, in milliseconds.
   *
   * <p>Clears any increment specified in a preceding call to {@link #setKeyCountIncrement(int)}.
   *
   * @param time The time increment, in milliseconds.
   */
  void setKeyTimeIncrement(long time);

  /**
   * Sets the position increment for key presses and accessibility actions, as a number of
   * increments that divide the duration of the media. For example, passing 20 will cause key
   * presses to increment/decrement the position by 1/20th of the duration (if known).
   *
   * <p>Clears any increment specified in a preceding call to {@link #setKeyTimeIncrement(long)}.
   *
   * @param count The number of increments that divide the duration of the media.
   */
  void setKeyCountIncrement(int count);

  /**
   * Sets the current position.
   *
   * @param position The current position to show, in milliseconds.
   */
  void setPosition(long position);

  /**
   * Sets the buffered position.
   *
   * @param bufferedPosition The current buffered position to show, in milliseconds.
   */
  void setBufferedPosition(long bufferedPosition);

  /**
   * Sets the duration.
   *
   * @param duration The duration to show, in milliseconds.
   */
  void setDuration(long duration);

  /**
   * Returns the preferred delay in milliseconds of media time after which the time bar position
   * should be updated.
   *
   * @return Preferred delay, in milliseconds of media time.
   */
  long getPreferredUpdateDelay();

  /**
   * Sets the times of ad groups and whether each ad group has been played.
   *
   * @param adGroupTimesMs An array where the first {@code adGroupCount} elements are the times of
   *     ad groups in milliseconds. May be {@code null} if there are no ad groups.
   * @param playedAdGroups An array where the first {@code adGroupCount} elements indicate whether
   *     the corresponding ad groups have been played. May be {@code null} if there are no ad
   *     groups.
   * @param adGroupCount The number of ad groups.
   */
  void setAdGroupTimesMs(
      @Nullable long[] adGroupTimesMs, @Nullable boolean[] playedAdGroups, int adGroupCount);

  /** Listener for scrubbing events. */
  interface OnScrubListener {

    /**
     * Called when the user starts moving the scrubber.
     *
     * @param timeBar The time bar.
     * @param position The scrub position in milliseconds.
     */
    void onScrubStart(TimeBar timeBar, long position);

    /**
     * Called when the user moves the scrubber.
     *
     * @param timeBar The time bar.
     * @param position The scrub position in milliseconds.
     */
    void onScrubMove(TimeBar timeBar, long position);

    /**
     * Called when the user stops moving the scrubber.
     *
     * @param timeBar The time bar.
     * @param position The scrub position in milliseconds.
     * @param canceled Whether scrubbing was canceled.
     */
    void onScrubStop(TimeBar timeBar, long position, boolean canceled);
  }
}