DefaultTimeBar


@UnstableApi
public class DefaultTimeBar extends View implements TimeBar


A time bar that shows a current position, buffered position, duration and ad markers.

A DefaultTimeBar can be customized by setting attributes, as outlined below.

Attributes

The following attributes can be set on a DefaultTimeBar when used in a layout XML file:
  • bar_height - Dimension for the height of the time bar.
  • touch_target_height - Dimension for the height of the area in which touch interactions with the time bar are handled. If no height is specified, this also determines the height of the view.
  • ad_marker_width - Dimension for the width of any ad markers shown on the bar. Ad markers are superimposed on the time bar to show the times at which ads will play.
  • scrubber_enabled_size - Dimension for the diameter of the circular scrubber handle when scrubbing is enabled but not in progress. Set to zero if no scrubber handle should be shown.
  • scrubber_disabled_size - Dimension for the diameter of the circular scrubber handle when scrubbing isn't enabled. Set to zero if no scrubber handle should be shown.
  • scrubber_dragged_size - Dimension for the diameter of the circular scrubber handle when scrubbing is in progress. Set to zero if no scrubber handle should be shown.
  • scrubber_drawable - Optional reference to a drawable to draw for the scrubber handle. If set, this overrides the default behavior, which is to draw a circle for the scrubber handle.
  • played_color - Color for the portion of the time bar representing media before the current playback position.
  • scrubber_color - Color for the scrubber handle.
  • buffered_color - Color for the portion of the time bar after the current played position up to the current buffered position.
  • unplayed_color - Color for the portion of the time bar after the current buffered position.
  • ad_marker_color - Color for unplayed ad markers.
  • played_ad_marker_color - Color for played ad markers.

Summary

Constants

static final int

Vertical gravity for progress bar to be located at the bottom in the view.

static final int

Vertical gravity for progress bar to be located at the center in the view.

static final int

Default color for ad markers.

static final int

Default width for ad markers, in dp.

static final int

Default height for the time bar, in dp.

static final int

Default color for the buffered portion of the time bar.

static final int

Default color for played ad markers.

static final int

Default color for the played portion of the time bar.

static final int

Default color for the scrubber handle.

static final int

Default diameter for the scrubber when disabled, in dp.

static final int

Default diameter for the scrubber when dragged, in dp.

static final int

Default diameter for the scrubber when enabled, in dp.

static final int

Default height for the touch target, in dp.

static final int

Default color for the unplayed portion of the time bar.

Public constructors

DefaultTimeBar(
    Context context,
    @Nullable AttributeSet attrs,
    int defStyleAttr
)
DefaultTimeBar(
    Context context,
    @Nullable AttributeSet attrs,
    int defStyleAttr,
    @Nullable AttributeSet timebarAttrs
)
DefaultTimeBar(
    Context context,
    @Nullable AttributeSet attrs,
    int defStyleAttr,
    @Nullable AttributeSet timebarAttrs,
    int defStyleRes
)

Public methods

void

Adds a listener for scrubbing events.

long

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

void
hideScrubber(boolean disableScrubberPadding)

Hides the scrubber handle.

void
hideScrubber(long hideAnimationDurationMs)

Hides the scrubber handle with animation.

void
void
onDraw(Canvas canvas)
void
void
boolean
onKeyDown(int keyCode, KeyEvent event)
void
onRtlPropertiesChanged(int layoutDirection)
boolean
boolean
void

Removes a listener for scrubbing events.

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

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

void
setAdMarkerColor(@ColorInt int adMarkerColor)

Sets the color for unplayed ad markers.

void
setBufferedColor(@ColorInt int bufferedColor)

Sets the color for the portion of the time bar after the current played position up to the current buffered position.

void
setBufferedPosition(long bufferedPosition)

Sets the buffered position.

void
setDuration(long duration)

Sets the duration.

void
setEnabled(boolean enabled)
void

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

void

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

void
setPlayedAdMarkerColor(@ColorInt int playedAdMarkerColor)

Sets the color for played ad markers.

void
setPlayedColor(@ColorInt int playedColor)

Sets the color for the portion of the time bar representing media before the playback position.

void
setPosition(long position)

Sets the current position.

void
setScrubberColor(@ColorInt int scrubberColor)

Sets the color for the scrubber handle.

void
setUnplayedColor(@ColorInt int unplayedColor)

Sets the color for the portion of the time bar after the current played position.

void

Shows the scrubber handle.

void
showScrubber(long showAnimationDurationMs)

Shows the scrubber handle with animation.

Protected methods

void
void
onFocusChanged(
    boolean gainFocus,
    int direction,
    @Nullable Rect previouslyFocusedRect
)
void
onLayout(boolean changed, int left, int top, int right, int bottom)
void
onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Inherited Constants

From android.view.View
static final int
static final int
static final int
static final int
static final int
static final int
static final Property<ViewFloat>
static final int
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE = "creditCardExpirationDate"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY = "creditCardExpirationDay"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH = "creditCardExpirationMonth"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR = "creditCardExpirationYear"
static final String
static final String
AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE = "creditCardSecurityCode"
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int
static final int
static final int
static final int
static final int
static final int
static final int[]
static final int[]
static final int[]
static final int[]
static final int
static final int
static final int
static final int
static final int
static final int
static final int
GONE = 8
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
KEEP_SCREEN_ON = 67108864
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
NO_ID = -1
static final int
static final int
static final int
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int[]
static final int[]
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final String
VIEW_LOG_TAG = "View"
static final int
static final int[]
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>

Inherited methods

From android.view.View
void
void
addExtraDataToAccessibilityNodeInfo(
    AccessibilityNodeInfo info,
    String extraDataKey,
    Bundle arguments
)
void
addFocusables(ArrayList<View> views, int direction)
void
void
void
void
void
ViewPropertyAnimator
void
void
boolean
void
void

This method is deprecated.

void
boolean
boolean
boolean
boolean
boolean
canScrollHorizontally(int direction)
boolean
canScrollVertically(int direction)
final void
void
final void
boolean
void
void
void
static int
combineMeasuredStates(int curState, int newState)
int
int
int
void
WindowInsets
int
int
int
AccessibilityNodeInfo
void
void

This method is deprecated.

WindowInsets
boolean
void
void
dispatchCreateViewTranslationRequest(
    Map<AutofillId, long[]> viewIds,
    int[] supportedFormats,
    TranslationCapability capability,
    List<ViewTranslationRequest> requests
)
void
boolean
void
void
dispatchDrawableHotspotChanged(float x, float y)
void
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
dispatchNestedFling(float velocityX, float velocityY, boolean consumed)
boolean
dispatchNestedPreFling(float velocityX, float velocityY)
boolean
dispatchNestedPrePerformAccessibilityAction(
    int action,
    Bundle arguments
)
boolean
dispatchNestedPreScroll(
    int dx,
    int dy,
    int[] consumed,
    int[] offsetInWindow
)
boolean
dispatchNestedScroll(
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    int[] offsetInWindow
)
void
dispatchPointerCaptureChanged(boolean hasCapture)
boolean
void
void
void
void
void
dispatchScrollCaptureSearch(
    Rect localVisibleRect,
    Point windowOffset,
    Consumer<ScrollCaptureTarget> targets
)
void
dispatchSetActivated(boolean activated)
void
dispatchSetPressed(boolean pressed)
void
dispatchSetSelected(boolean selected)
void
void

This method is deprecated.

boolean
boolean
boolean
dispatchUnhandledMove(View focused, int direction)
void
dispatchVisibilityChanged(View changedView, int visibility)
void
dispatchWindowFocusChanged(boolean hasFocus)
void
void
WindowInsets
WindowInsetsAnimation.Bounds
void

This method is deprecated.

void
void
draw(Canvas canvas)
void
drawableHotspotChanged(float x, float y)
View
final OnBackInvokedDispatcher
final T
<T extends View> findViewById(int id)
final T
<T extends View> findViewWithTag(Object tag)
void
findViewsWithText(
    ArrayList<View> outViews,
    CharSequence searched,
    int flags
)
boolean

This method is deprecated.

View
focusSearch(int direction)
void
forceHasOverlappingRendering(boolean hasOverlappingRendering)
void
boolean
void
generateDisplayHash(
    String hashAlgorithm,
    Rect bounds,
    Executor executor,
    DisplayHashResultCallback callback
)
static int
CharSequence
View.AccessibilityDelegate
int
AccessibilityNodeProvider
CharSequence
int
int
String
String
float
Animation
Matrix
IBinder
int[]
Map<IntegerInteger>
String[]
final AutofillId
int
AutofillValue
Drawable
BlendMode
ColorStateList
PorterDuff.Mode
int
final int
float
int
float
Rect
boolean
final boolean
final ContentCaptureSession
CharSequence
final Context
ContextMenu.ContextMenuInfo
final boolean
static int
getDefaultSize(int size, int measureSpec)
Display
final int[]
Bitmap

This method is deprecated.

int

This method is deprecated.

int

This method is deprecated.

void
long
float
int
boolean
boolean
int
ArrayList<View>
getFocusables(int direction)
void
Drawable
int
BlendMode
ColorStateList
PorterDuff.Mode
boolean
getGlobalVisibleRect(Rect r, Point globalOffset)
Handler
float
float
float
float
Runnable
final boolean
final int
void
getHitRect(Rect outRect)
int
int
Drawable
Drawable
int
int
int
int
boolean
KeyEvent.DispatcherState
int
int
int
ViewGroup.LayoutParams
final int
float
int
final boolean
void
getLocationInSurface(int[] location)
void
getLocationInWindow(int[] outLocation)
void
getLocationOnScreen(int[] outLocation)
Matrix
final int
final int
final int
final int
final int
int
int
int
int
int
int
int
int
View.OnFocusChangeListener
int
ViewOutlineProvider
int
int
ViewOverlay
int
int
int
int
int
int
final ViewParent
ViewParent
float
float
PointerIcon
final List<Rect>
String[]
Resources
final boolean
final int
float
int
AttachedSurfaceControl
View
WindowInsets
float
float
float
float
float
int
int
int
int
int
int
final int
final int
int
int
final CharSequence
StateListAnimator
int
int
List<Rect>
int

This method is deprecated.

Object
int
int
CharSequence
final int
float
int
TouchDelegate
ArrayList<View>
float
String
float
float
float
long
int
int
Drawable
Drawable
int
ViewTranslationResponse
ViewTreeObserver
int
final int
int
WindowId
WindowInsetsController
int

This method is deprecated.

IBinder
int
void
float
float
float
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
static View
inflate(Context context, int resource, ViewGroup root)
void

This method is deprecated.

void
void
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean

This method is deprecated.

boolean
boolean
final boolean
final boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
final boolean
final boolean
boolean
boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
final boolean
boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
View
keyboardNavigationClusterSearch(View currentCluster, int direction)
void
layout(int l, int t, int r, int b)
final void
measure(int widthMeasureSpec, int heightMeasureSpec)
static int[]
mergeDrawableStates(int[] baseState, int[] additionalState)
void
offsetLeftAndRight(int offset)
void
offsetTopAndBottom(int offset)
void
void
WindowInsets
void
void
boolean
boolean
void
void
int[]
onCreateDrawableState(int extraSpace)
InputConnection
void
onCreateViewTranslationRequest(
    int[] supportedFormats,
    Consumer<ViewTranslationRequest> requestsCollector
)
void
onCreateVirtualViewTranslationRequests(
    long[] virtualIds,
    int[] supportedFormats,
    Consumer<ViewTranslationRequest> requestsCollector
)
void
void
onDisplayHint(int hint)
boolean
void
final void
boolean
void
void
boolean
void
onHoverChanged(boolean hovered)
boolean
boolean
onKeyLongPress(int keyCode, KeyEvent event)
boolean
onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)
boolean
onKeyPreIme(int keyCode, KeyEvent event)
boolean
onKeyShortcut(int keyCode, KeyEvent event)
boolean
onKeyUp(int keyCode, KeyEvent event)
void
onOverScrolled(
    int scrollX,
    int scrollY,
    boolean clampedX,
    boolean clampedY
)
void
onPointerCaptureChange(boolean hasCapture)
void
void
onProvideAutofillStructure(ViewStructure structure, int flags)
void
void
void
void
ContentInfo
PointerIcon
onResolvePointerIcon(MotionEvent event, int pointerIndex)
void
Parcelable
void
onScreenStateChanged(int screenState)
void
onScrollCaptureSearch(
    Rect localVisibleRect,
    Point windowOffset,
    Consumer<ScrollCaptureTarget> targets
)
void
onScrollChanged(int l, int t, int oldl, int oldt)
boolean
onSetAlpha(int alpha)
void
onSizeChanged(int w, int h, int oldw, int oldh)
void
boolean
void
void
void
onVisibilityAggregated(boolean isVisible)
void
onVisibilityChanged(View changedView, int visibility)
void
onWindowFocusChanged(boolean hasWindowFocus)
void

This method is deprecated.

void
onWindowVisibilityChanged(int visibility)
boolean
overScrollBy(
    int deltaX,
    int deltaY,
    int scrollX,
    int scrollY,
    int scrollRangeX,
    int scrollRangeY,
    int maxOverScrollX,
    int maxOverScrollY,
    boolean isTouchEvent
)
boolean
boolean
performContextClick(float x, float y)
boolean
performHapticFeedback(int feedbackConstant)
boolean
ContentInfo
void
playSoundEffect(int soundConstant)
boolean
post(Runnable action)
boolean
postDelayed(Runnable action, long delayMillis)
void
void
postInvalidateDelayed(long delayMilliseconds)
void
void
void
postOnAnimationDelayed(Runnable action, long delayMillis)
void
void
boolean
void
void
void
void
void

This method is deprecated.

final boolean
final boolean
void
void
boolean
final void
final T
<T extends View> requireViewById(int id)
void
static int
resolveSize(int size, int measureSpec)
static int
resolveSizeAndState(int size, int measureSpec, int childMeasuredState)
boolean
void
final void
saveAttributeDataForStyleable(
    Context context,
    int[] styleable,
    AttributeSet attrs,
    TypedArray t,
    int defStyleAttr,
    int defStyleRes
)
void
void
scheduleDrawable(Drawable who, Runnable what, long when)
void
scrollBy(int x, int y)
void
scrollTo(int x, int y)
void
sendAccessibilityEvent(int eventType)
void
void
setAccessibilityDataSensitive(int accessibilityDataSensitive)
void
void
setAccessibilityHeading(boolean isHeading)
void
void
setAccessibilityPaneTitle(CharSequence accessibilityPaneTitle)
void
void
void
setActivated(boolean activated)
void
setAllowClickWhenDisabled(boolean clickableWhenDisabled)
void
void
void
setAlpha(float alpha)
void
void
void
setAutoHandwritingEnabled(boolean enabled)
void
setAutofillHints(String[] autofillHints)
void
void
setBackground(Drawable background)
void
setBackgroundColor(int color)
void

This method is deprecated.

void
void
void
void
final void
setBottom(int bottom)
void
setCameraDistance(float distance)
void
setClickable(boolean clickable)
void
setClipBounds(Rect clipBounds)
void
setClipToOutline(boolean clipToOutline)
void
void
setContentDescription(CharSequence contentDescription)
void
setContextClickable(boolean contextClickable)
void
setDefaultFocusHighlightEnabled(boolean defaultFocusHighlightEnabled)
void

This method is deprecated.

void
setDrawingCacheEnabled(boolean enabled)

This method is deprecated.

void

This method is deprecated.

void
void
setElevation(float elevation)
void
setFadingEdgeLength(int length)
void
void
setFitsSystemWindows(boolean fitSystemWindows)
void
setFocusable(boolean focusable)
void
setFocusableInTouchMode(boolean focusableInTouchMode)
void
setFocusedByDefault(boolean isFocusedByDefault)
void
setForceDarkAllowed(boolean allow)
void
setForeground(Drawable foreground)
void
setForegroundGravity(int gravity)
void
void
void
void
setHandwritingBoundsOffsets(
    float offsetLeft,
    float offsetTop,
    float offsetRight,
    float offsetBottom
)
void
void
setHapticFeedbackEnabled(boolean hapticFeedbackEnabled)
void
setHasTransientState(boolean hasTransientState)
void
setHorizontalFadingEdgeEnabled(boolean horizontalFadingEdgeEnabled)
void
setHorizontalScrollBarEnabled(boolean horizontalScrollBarEnabled)
void
void
void
setHovered(boolean hovered)
void
setId(int id)
void
void
void
void
setIsCredential(boolean isCredential)
void
setIsHandwritingDelegate(boolean isHandwritingDelegate)
void
setKeepScreenOn(boolean keepScreenOn)
void
setKeyboardNavigationCluster(boolean isCluster)
void
setLabelFor(int id)
void
void
setLayerType(int layerType, Paint paint)
void
setLayoutDirection(int layoutDirection)
void
final void
setLeft(int left)
final void
setLeftTopRightBottom(int left, int top, int right, int bottom)
void
setLongClickable(boolean longClickable)
final void
setMeasuredDimension(int measuredWidth, int measuredHeight)
void
setMinimumHeight(int minHeight)
void
setMinimumWidth(int minWidth)
void
setNestedScrollingEnabled(boolean enabled)
void
setNextClusterForwardId(int nextClusterForwardId)
void
setNextFocusDownId(int nextFocusDownId)
void
setNextFocusForwardId(int nextFocusForwardId)
void
setNextFocusLeftId(int nextFocusLeftId)
void
setNextFocusRightId(int nextFocusRightId)
void
setNextFocusUpId(int nextFocusUpId)
void
void
void
void
void
void
void
void
void
void
void
void
setOnReceiveContentListener(
    String[] mimeTypes,
    OnReceiveContentListener listener
)
void
void

This method is deprecated.

void
void
void
void
void
setOverScrollMode(int overScrollMode)
void
setPadding(int left, int top, int right, int bottom)
void
setPaddingRelative(int start, int top, int end, int bottom)
void
setPivotX(float pivotX)
void
setPivotY(float pivotY)
void
final void
setPreferKeepClear(boolean preferKeepClear)
final void
void
setPressed(boolean pressed)
void
final void
setRevealOnFocusHint(boolean revealOnFocus)
final void
setRight(int right)
void
setRotation(float rotation)
void
setRotationX(float rotationX)
void
setRotationY(float rotationY)
void
setSaveEnabled(boolean enabled)
void
setSaveFromParentEnabled(boolean enabled)
void
setScaleX(float scaleX)
void
setScaleY(float scaleY)
void
setScreenReaderFocusable(boolean screenReaderFocusable)
void
setScrollBarDefaultDelayBeforeFade(
    int scrollBarDefaultDelayBeforeFade
)
void
setScrollBarFadeDuration(int scrollBarFadeDuration)
void
setScrollBarSize(int scrollBarSize)
void
setScrollBarStyle(int style)
final void
void
void
setScrollContainer(boolean isScrollContainer)
void
setScrollIndicators(int indicators)
void
setScrollX(int value)
void
setScrollY(int value)
void
setScrollbarFadingEnabled(boolean fadeScrollbars)
void
setSelected(boolean selected)
void
setSoundEffectsEnabled(boolean soundEffectsEnabled)
void
void
void
void
setSystemUiVisibility(int visibility)

This method is deprecated.

void
void
setTextAlignment(int textAlignment)
void
setTextDirection(int textDirection)
void
final void
setTop(int top)
void
void
setTransitionAlpha(float alpha)
final void
setTransitionName(String transitionName)
void
setTransitionVisibility(int visibility)
void
setTranslationX(float translationX)
void
setTranslationY(float translationY)
void
setTranslationZ(float translationZ)
void
setVerticalFadingEdgeEnabled(boolean verticalFadingEdgeEnabled)
void
setVerticalScrollBarEnabled(boolean verticalScrollBarEnabled)
void
void
void
void
void
setVisibility(int visibility)
void
setWillNotCacheDrawing(boolean willNotCacheDrawing)

This method is deprecated.

void
setWillNotDraw(boolean willNotDraw)
void
void
setX(float x)
void
setY(float y)
void
setZ(float z)
boolean
ActionMode
void
final boolean
startDrag(
    ClipData data,
    View.DragShadowBuilder shadowBuilder,
    Object myLocalState,
    int flags
)

This method is deprecated.

final boolean
startDragAndDrop(
    ClipData data,
    View.DragShadowBuilder shadowBuilder,
    Object myLocalState,
    int flags
)
boolean
void
String
void
void
void
final void
boolean
boolean

This method is deprecated.

boolean

Constants

BAR_GRAVITY_BOTTOM

public static final int BAR_GRAVITY_BOTTOM = 1

Vertical gravity for progress bar to be located at the bottom in the view.

BAR_GRAVITY_CENTER

public static final int BAR_GRAVITY_CENTER = 0

Vertical gravity for progress bar to be located at the center in the view.

DEFAULT_AD_MARKER_COLOR

public static final int DEFAULT_AD_MARKER_COLOR = -1291845888

Default color for ad markers.

DEFAULT_AD_MARKER_WIDTH_DP

public static final int DEFAULT_AD_MARKER_WIDTH_DP = 4

Default width for ad markers, in dp.

DEFAULT_BAR_HEIGHT_DP

public static final int DEFAULT_BAR_HEIGHT_DP = 4

Default height for the time bar, in dp.

DEFAULT_BUFFERED_COLOR

public static final int DEFAULT_BUFFERED_COLOR = -855638017

Default color for the buffered portion of the time bar.

DEFAULT_PLAYED_AD_MARKER_COLOR

public static final int DEFAULT_PLAYED_AD_MARKER_COLOR = 872414976

Default color for played ad markers.

DEFAULT_PLAYED_COLOR

public static final int DEFAULT_PLAYED_COLOR = -1

Default color for the played portion of the time bar.

DEFAULT_SCRUBBER_COLOR

public static final int DEFAULT_SCRUBBER_COLOR = -1

Default color for the scrubber handle.

DEFAULT_SCRUBBER_DISABLED_SIZE_DP

public static final int DEFAULT_SCRUBBER_DISABLED_SIZE_DP = 0

Default diameter for the scrubber when disabled, in dp.

DEFAULT_SCRUBBER_DRAGGED_SIZE_DP

public static final int DEFAULT_SCRUBBER_DRAGGED_SIZE_DP = 16

Default diameter for the scrubber when dragged, in dp.

DEFAULT_SCRUBBER_ENABLED_SIZE_DP

public static final int DEFAULT_SCRUBBER_ENABLED_SIZE_DP = 12

Default diameter for the scrubber when enabled, in dp.

DEFAULT_TOUCH_TARGET_HEIGHT_DP

public static final int DEFAULT_TOUCH_TARGET_HEIGHT_DP = 26

Default height for the touch target, in dp.

DEFAULT_UNPLAYED_COLOR

public static final int DEFAULT_UNPLAYED_COLOR = 872415231

Default color for the unplayed portion of the time bar.

Public constructors

DefaultTimeBar

public DefaultTimeBar(Context context)

DefaultTimeBar

public DefaultTimeBar(Context context, @Nullable AttributeSet attrs)

DefaultTimeBar

public DefaultTimeBar(
    Context context,
    @Nullable AttributeSet attrs,
    int defStyleAttr
)

DefaultTimeBar

public DefaultTimeBar(
    Context context,
    @Nullable AttributeSet attrs,
    int defStyleAttr,
    @Nullable AttributeSet timebarAttrs
)

DefaultTimeBar

public DefaultTimeBar(
    Context context,
    @Nullable AttributeSet attrs,
    int defStyleAttr,
    @Nullable AttributeSet timebarAttrs,
    int defStyleRes
)

Public methods

addListener

public void addListener(TimeBar.OnScrubListener listener)

Adds a listener for scrubbing events.

Parameters
TimeBar.OnScrubListener listener

The listener to add.

getPreferredUpdateDelay

public long getPreferredUpdateDelay()

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

Returns
long

Preferred delay, in milliseconds of media time.

hideScrubber

public void hideScrubber(boolean disableScrubberPadding)

Hides the scrubber handle.

hideScrubber

public void hideScrubber(long hideAnimationDurationMs)

Hides the scrubber handle with animation.

Parameters
long hideAnimationDurationMs

The duration for scrubber hiding animation.

jumpDrawablesToCurrentState

public void jumpDrawablesToCurrentState()

onDraw

public void onDraw(Canvas canvas)

onInitializeAccessibilityEvent

public void onInitializeAccessibilityEvent(AccessibilityEvent event)

onInitializeAccessibilityNodeInfo

public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)

onKeyDown

public boolean onKeyDown(int keyCode, KeyEvent event)

onRtlPropertiesChanged

public void onRtlPropertiesChanged(int layoutDirection)

onTouchEvent

public boolean onTouchEvent(MotionEvent event)

performAccessibilityAction

public boolean performAccessibilityAction(int action, @Nullable Bundle args)

removeListener

public void removeListener(TimeBar.OnScrubListener listener)

Removes a listener for scrubbing events.

Parameters
TimeBar.OnScrubListener listener

The listener to remove.

setAdGroupTimesMs

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

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

Parameters
@Nullable long[] 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.

@Nullable boolean[] 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.

int adGroupCount

The number of ad groups.

setAdMarkerColor

public void setAdMarkerColor(@ColorInt int adMarkerColor)

Sets the color for unplayed ad markers.

Parameters
@ColorInt int adMarkerColor

The color for unplayed ad markers.

setBufferedColor

public void setBufferedColor(@ColorInt int bufferedColor)

Sets the color for the portion of the time bar after the current played position up to the current buffered position.

Parameters
@ColorInt int bufferedColor

The color for the portion of the time bar after the current played position up to the current buffered position.

setBufferedPosition

public void setBufferedPosition(long bufferedPosition)

Sets the buffered position.

Parameters
long bufferedPosition

The current buffered position to show, in milliseconds.

setDuration

public void setDuration(long duration)

Sets the duration.

Parameters
long duration

The duration to show, in milliseconds.

setEnabled

public void setEnabled(boolean enabled)

setKeyCountIncrement

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

Parameters
int count

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

setKeyTimeIncrement

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

Parameters
long time

The time increment, in milliseconds.

setPlayedAdMarkerColor

public void setPlayedAdMarkerColor(@ColorInt int playedAdMarkerColor)

Sets the color for played ad markers.

Parameters
@ColorInt int playedAdMarkerColor

The color for played ad markers.

setPlayedColor

public void setPlayedColor(@ColorInt int playedColor)

Sets the color for the portion of the time bar representing media before the playback position.

Parameters
@ColorInt int playedColor

The color for the portion of the time bar representing media before the playback position.

setPosition

public void setPosition(long position)

Sets the current position.

Parameters
long position

The current position to show, in milliseconds.

setScrubberColor

public void setScrubberColor(@ColorInt int scrubberColor)

Sets the color for the scrubber handle.

Parameters
@ColorInt int scrubberColor

The color for the scrubber handle.

setUnplayedColor

public void setUnplayedColor(@ColorInt int unplayedColor)

Sets the color for the portion of the time bar after the current played position.

Parameters
@ColorInt int unplayedColor

The color for the portion of the time bar after the current played position.

showScrubber

public void showScrubber()

Shows the scrubber handle.

showScrubber

public void showScrubber(long showAnimationDurationMs)

Shows the scrubber handle with animation.

Parameters
long showAnimationDurationMs

The duration for scrubber showing animation.

Protected methods

drawableStateChanged

protected void drawableStateChanged()

onFocusChanged

protected void onFocusChanged(
    boolean gainFocus,
    int direction,
    @Nullable Rect previouslyFocusedRect
)

onLayout

protected void onLayout(boolean changed, int left, int top, int right, int bottom)

onMeasure

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)