@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(); }
private void showController(boolean showIndefinitely) { if (!useController) { return; } controller.setShowTimeoutMs(showIndefinitely ? 0 : controllerShowTimeoutMs); controller.show(); }
/** * Sets whether the playback controls can be shown. If set to {@code false} the playback controls * are never visible and are disconnected from the player. * * @param useController Whether the playback controls can be shown. */ public void setUseController(boolean useController) { Assertions.checkState(!useController || controller != null); if (this.useController == useController) { return; } this.useController = useController; if (useController) { controller.setPlayer(player); } else if (controller != null) { controller.hide(); controller.setPlayer(null); } }
/** * 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(); } }
/** Hides the controller. */ public void hide() { if (isVisible()) { setVisibility(GONE); if (visibilityListener != null) { visibilityListener.onVisibilityChange(getVisibility()); } removeCallbacks(updateProgressAction); removeCallbacks(hideAction); hideAtMs = C.TIME_UNSET; } }
/** * 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(); }
/** Returns whether the controller is currently visible. */ public boolean isControllerVisible() { return controller != null && controller.isVisible(); }
/** 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); } } }
/** Hides the playback controls. Does nothing if playback controls are disabled. */ public void hideController() { if (controller != null) { controller.hide(); } }
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 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(); } }
this.controller = new PlayerControlView(context, null, 0, attrs); controller.setLayoutParams(controllerPlaceholder.getLayoutParams()); ViewGroup parent = ((ViewGroup) controllerPlaceholder.getParent()); int controllerIndex = parent.indexOfChild(controllerPlaceholder);
private void updateProgress() { if (!isVisible() || !isAttachedToWindow) { return; removeCallbacks(updateProgressAction); int playbackState = player == null ? Player.STATE_IDLE : player.getPlaybackState(); if (playbackState != Player.STATE_IDLE && playbackState != Player.STATE_ENDED) { delayMs = 1000; postDelayed(updateProgressAction, delayMs);
private PlayerManager( QueuePositionListener queuePositionListener, PlayerView localPlayerView, PlayerControlView castControlView, Context context, CastContext castContext) { this.queuePositionListener = queuePositionListener; this.localPlayerView = localPlayerView; this.castControlView = castControlView; mediaQueue = new ArrayList<>(); currentItemIndex = C.INDEX_UNSET; concatenatingMediaSource = new ConcatenatingMediaSource(); DefaultTrackSelector trackSelector = new DefaultTrackSelector(); RenderersFactory renderersFactory = new DefaultRenderersFactory(context); exoPlayer = ExoPlayerFactory.newSimpleInstance(context, renderersFactory, trackSelector); exoPlayer.addListener(this); localPlayerView.setPlayer(exoPlayer); castPlayer = new CastPlayer(castContext); castPlayer.addListener(this); castPlayer.setSessionAvailabilityListener(this); castControlView.setPlayer(castPlayer); }
/** * Called to process media key events. Any {@link KeyEvent} can be passed but only media key * events will be handled. Does nothing if playback controls are disabled. * * @param event A key event. * @return Whether the key event was handled. */ public boolean dispatchMediaKeyEvent(KeyEvent event) { return useController && controller.dispatchMediaKeyEvent(event); }
/** * Sets the fast forward increment in milliseconds. * * @param fastForwardMs The fast forward increment in milliseconds. A non-positive value will * cause the fast forward button to be disabled. */ public void setFastForwardIncrementMs(int fastForwardMs) { Assertions.checkState(controller != null); controller.setFastForwardIncrementMs(fastForwardMs); }
/** * Sets the {@link ControlDispatcher}. * * @param controlDispatcher The {@link ControlDispatcher}, or null to use {@link * DefaultControlDispatcher}. */ public void setControlDispatcher(@Nullable ControlDispatcher controlDispatcher) { Assertions.checkState(controller != null); controller.setControlDispatcher(controlDispatcher); }