/** Returns whether the controller is currently visible. */ public boolean isControllerVisible() { return controller != null && controller.isVisible(); }
/** * Sets the playback controls timeout. The playback controls are automatically hidden after this * duration of time has elapsed without user input. * * @param showTimeoutMs The duration in milliseconds. A non-positive value will cause the controls * to remain visible indefinitely. */ public void setShowTimeoutMs(int showTimeoutMs) { this.showTimeoutMs = showTimeoutMs; if (isVisible()) { // Reset the timeout. hideAfterTimeout(); } }
private void updateShuffleButton() { if (!isVisible() || !isAttachedToWindow || shuffleButton == null) { return; } if (!showShuffleButton) { shuffleButton.setVisibility(View.GONE); } else if (player == null) { setButtonEnabled(false, shuffleButton); } else { shuffleButton.setAlpha(player.getShuffleModeEnabled() ? 1f : 0.3f); shuffleButton.setEnabled(true); shuffleButton.setVisibility(View.VISIBLE); } }
private boolean toggleControllerVisibility() { if (!useController || player == null) { return false; } if (!controller.isVisible()) { maybeShowController(true); } else if (controllerHideOnTouch) { controller.hide(); } return true; }
/** * Sets the playback controls timeout. The playback controls are automatically hidden after this * duration of time has elapsed without user input and with playback or buffering in progress. * * @param controllerShowTimeoutMs The timeout in milliseconds. A non-positive value will cause the * controller to remain visible indefinitely. */ public void setControllerShowTimeoutMs(int controllerShowTimeoutMs) { Assertions.checkState(controller != null); this.controllerShowTimeoutMs = controllerShowTimeoutMs; if (controller.isVisible()) { // Update the controller's timeout if necessary. showController(); } }
private void updatePlayPauseButton() { if (!isVisible() || !isAttachedToWindow) { return; } boolean requestPlayPauseFocus = false; boolean playing = isPlaying(); if (playButton != null) { requestPlayPauseFocus |= playing && playButton.isFocused(); playButton.setVisibility(playing ? View.GONE : View.VISIBLE); } if (pauseButton != null) { requestPlayPauseFocus |= !playing && pauseButton.isFocused(); pauseButton.setVisibility(!playing ? View.GONE : View.VISIBLE); } if (requestPlayPauseFocus) { requestPlayPauseFocus(); } }
/** Shows the playback controls, but only if forced or shown indefinitely. */ private void maybeShowController(boolean isForced) { if (isPlayingAd() && controllerHideDuringAds) { return; } if (useController) { boolean wasShowingIndefinitely = controller.isVisible() && controller.getShowTimeoutMs() <= 0; boolean shouldShowIndefinitely = shouldShowControllerIndefinitely(); if (isForced || wasShowingIndefinitely || shouldShowIndefinitely) { showController(shouldShowIndefinitely); } } }
private void updateRepeatModeButton() { if (!isVisible() || !isAttachedToWindow || repeatToggleButton == null) { return;
@Override public void onAttachedToWindow() { super.onAttachedToWindow(); isAttachedToWindow = true; if (hideAtMs != C.TIME_UNSET) { long delayMs = hideAtMs - SystemClock.uptimeMillis(); if (delayMs <= 0) { hide(); } else { postDelayed(hideAction, delayMs); } } else if (isVisible()) { hideAfterTimeout(); } updateAll(); }
/** Hides the controller. */ public void hide() { if (isVisible()) { setVisibility(GONE); if (visibilityListener != null) { visibilityListener.onVisibilityChange(getVisibility()); } removeCallbacks(updateProgressAction); removeCallbacks(hideAction); hideAtMs = C.TIME_UNSET; } }
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (player != null && player.isPlayingAd()) { // Focus any overlay UI now, in case it's provided by a WebView whose contents may update // dynamically. This is needed to make the "Skip ad" button focused on Android TV when using // IMA [Internal: b/62371030]. overlayFrameLayout.requestFocus(); return super.dispatchKeyEvent(event); } boolean isDpadWhenControlHidden = isDpadKey(event.getKeyCode()) && useController && !controller.isVisible(); boolean handled = isDpadWhenControlHidden || dispatchMediaKeyEvent(event) || super.dispatchKeyEvent(event); if (handled) { maybeShowController(true); } return handled; }
/** * Shows the playback controls. If {@link #getShowTimeoutMs()} is positive then the controls will * be automatically hidden after this duration of time has elapsed without user input. */ public void show() { if (!isVisible()) { setVisibility(VISIBLE); if (visibilityListener != null) { visibilityListener.onVisibilityChange(getVisibility()); } updateAll(); requestPlayPauseFocus(); } // Call hideAfterTimeout even if already visible to reset the timeout. hideAfterTimeout(); }
private void updateProgress() { if (!isVisible() || !isAttachedToWindow) { return;
private void updateNavigation() { if (!isVisible() || !isAttachedToWindow) { return; } Timeline timeline = player != null ? player.getCurrentTimeline() : null; boolean haveNonEmptyTimeline = timeline != null && !timeline.isEmpty(); boolean isSeekable = false; boolean enablePrevious = false; boolean enableNext = false; if (haveNonEmptyTimeline && !player.isPlayingAd()) { int windowIndex = player.getCurrentWindowIndex(); timeline.getWindow(windowIndex, window); isSeekable = window.isSeekable; enablePrevious = isSeekable || !window.isDynamic || player.hasPrevious(); enableNext = window.isDynamic || player.hasNext(); } setButtonEnabled(enablePrevious, previousButton); setButtonEnabled(enableNext, nextButton); setButtonEnabled(fastForwardMs > 0 && isSeekable, fastForwardButton); setButtonEnabled(rewindMs > 0 && isSeekable, rewindButton); if (timeBar != null) { timeBar.setEnabled(isSeekable); } }
@Override public boolean onDown(MotionEvent e) { maxVerticalMovement = 0; canUseWipeControls = !controlView.isVisible(); return super.onDown(e); }
@Override public boolean onTouchEvent(MotionEvent ev) { if (!useController || player == null || ev.getActionMasked() != MotionEvent.ACTION_DOWN) { return false; } if (!controller.isVisible()) { maybeShowController(true); } else if (controllerHideOnTouch) { controller.hide(); } return true; }
public void toggleControls() { if (controlView.isVisible()) { controlView.hide(); } else { controlView.show(); } }
/** * Sets the playback controls timeout. The playback controls are automatically hidden after this * duration of time has elapsed without user input and with playback or buffering in progress. * * @param controllerShowTimeoutMs The timeout in milliseconds. A non-positive value will cause the * controller to remain visible indefinitely. */ public void setControllerShowTimeoutMs(int controllerShowTimeoutMs) { Assertions.checkState(controller != null); this.controllerShowTimeoutMs = controllerShowTimeoutMs; if (controller.isVisible()) { // Update the controller's timeout if necessary. showController(); } }
/** * Shows the playback controls, but only if forced or shown indefinitely. */ private void maybeShowController(boolean isForced) { if (isPlayingAd() && controllerHideDuringAds) { return; } if (useController) { boolean wasShowingIndefinitely = controller.isVisible() && controller.getShowTimeoutMs() <= 0; boolean shouldShowIndefinitely = shouldShowControllerIndefinitely(); if (isForced || wasShowingIndefinitely || shouldShowIndefinitely) { showController(shouldShowIndefinitely); } } }
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (player != null && player.isPlayingAd()) { // Focus any overlay UI now, in case it's provided by a WebView whose contents may update // dynamically. This is needed to make the "Skip ad" button focused on Android TV when using // IMA [Internal: b/62371030]. overlayFrameLayout.requestFocus(); return super.dispatchKeyEvent(event); } boolean isDpadWhenControlHidden = isDpadKey(event.getKeyCode()) && useController && !controller.isVisible(); maybeShowController(true); return isDpadWhenControlHidden || dispatchMediaKeyEvent(event) || super.dispatchKeyEvent(event); }