Improve //region comments in player UIs
This commit is contained in:
parent
fa25ecf521
commit
6559416bd8
3 changed files with 173 additions and 111 deletions
|
@ -88,6 +88,12 @@ public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutCh
|
||||||
// fullscreen player
|
// fullscreen player
|
||||||
private ItemTouchHelper itemTouchHelper;
|
private ItemTouchHelper itemTouchHelper;
|
||||||
|
|
||||||
|
|
||||||
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
// Constructor, setup, destroy
|
||||||
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
//region Constructor, setup, destroy
|
||||||
|
|
||||||
public MainPlayerUi(@NonNull final Player player,
|
public MainPlayerUi(@NonNull final Player player,
|
||||||
@NonNull final PlayerBinding playerBinding) {
|
@NonNull final PlayerBinding playerBinding) {
|
||||||
super(player, playerBinding);
|
super(player, playerBinding);
|
||||||
|
@ -272,12 +278,14 @@ public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutCh
|
||||||
resources.getDimensionPixelSize(R.dimen.player_main_buttons_padding)
|
resources.getDimensionPixelSize(R.dimen.player_main_buttons_padding)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Broadcast receiver
|
// Broadcast receiver
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
//region Broadcast receiver
|
//region Broadcast receiver
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBroadcastReceived(final Intent intent) {
|
public void onBroadcastReceived(final Intent intent) {
|
||||||
super.onBroadcastReceived(intent);
|
super.onBroadcastReceived(intent);
|
||||||
|
@ -313,6 +321,7 @@ public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutCh
|
||||||
// Fragment binding
|
// Fragment binding
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
//region Fragment binding
|
//region Fragment binding
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFragmentListenerSet() {
|
public void onFragmentListenerSet() {
|
||||||
super.onFragmentListenerSet();
|
super.onFragmentListenerSet();
|
||||||
|
@ -351,13 +360,11 @@ public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutCh
|
||||||
}
|
}
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
private void showHideKodiButton() {
|
|
||||||
// show kodi button if it supports the current service and it is enabled in settings
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
@Nullable final PlayQueue playQueue = player.getPlayQueue();
|
// Playback states
|
||||||
binding.playWithKodi.setVisibility(playQueue != null && playQueue.getItem() != null
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
&& KoreUtils.shouldShowPlayWithKodi(context, playQueue.getItem().getServiceId())
|
//region Playback states
|
||||||
? View.VISIBLE : View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdateProgress(final int currentProgress,
|
public void onUpdateProgress(final int currentProgress,
|
||||||
|
@ -373,6 +380,22 @@ public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutCh
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlaying() {
|
||||||
|
super.onPlaying();
|
||||||
|
checkLandscape();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCompleted() {
|
||||||
|
super.onCompleted();
|
||||||
|
if (isFullscreen) {
|
||||||
|
toggleFullscreen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Controls showing / hiding
|
// Controls showing / hiding
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
@ -457,22 +480,21 @@ public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutCh
|
||||||
return Math.min(bitmap.getHeight(), screenHeight);
|
return Math.min(bitmap.getHeight(), screenHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showHideKodiButton() {
|
||||||
|
// show kodi button if it supports the current service and it is enabled in settings
|
||||||
|
@Nullable final PlayQueue playQueue = player.getPlayQueue();
|
||||||
|
binding.playWithKodi.setVisibility(playQueue != null && playQueue.getItem() != null
|
||||||
|
&& KoreUtils.shouldShowPlayWithKodi(context, playQueue.getItem().getServiceId())
|
||||||
|
? View.VISIBLE : View.GONE);
|
||||||
|
}
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPlaying() {
|
|
||||||
super.onPlaying();
|
|
||||||
checkLandscape();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCompleted() {
|
|
||||||
super.onCompleted();
|
|
||||||
if (isFullscreen) {
|
|
||||||
toggleFullscreen();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
// Captions (text tracks)
|
||||||
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
//region Captions (text tracks)
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setupSubtitleView(float captionScale) {
|
protected void setupSubtitleView(float captionScale) {
|
||||||
|
@ -482,8 +504,7 @@ public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutCh
|
||||||
binding.subtitleView.setFixedTextSize(
|
binding.subtitleView.setFixedTextSize(
|
||||||
TypedValue.COMPLEX_UNIT_PX, minimumLength / captionRatioInverse);
|
TypedValue.COMPLEX_UNIT_PX, minimumLength / captionRatioInverse);
|
||||||
}
|
}
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -798,6 +819,7 @@ public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutCh
|
||||||
// Click listeners
|
// Click listeners
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
//region Click listeners
|
//region Click listeners
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(final View v) {
|
public void onClick(final View v) {
|
||||||
if (v.getId() == binding.screenRotationButton.getId()) {
|
if (v.getId() == binding.screenRotationButton.getId()) {
|
||||||
|
@ -855,9 +877,9 @@ public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutCh
|
||||||
|
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Video size, resize, orientation, fullscreen
|
// Video size, orientation, fullscreen
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
//region Video size, resize, orientation, fullscreen
|
//region Video size, orientation, fullscreen
|
||||||
|
|
||||||
private void setupScreenRotationButton() {
|
private void setupScreenRotationButton() {
|
||||||
binding.screenRotationButton.setVisibility(globalScreenOrientationLocked(context)
|
binding.screenRotationButton.setVisibility(globalScreenOrientationLocked(context)
|
||||||
|
@ -941,9 +963,6 @@ public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutCh
|
||||||
// Getters
|
// Getters
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
//region Getters
|
//region Getters
|
||||||
public PlayerBinding getBinding() {
|
|
||||||
return binding;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<AppCompatActivity> getParentActivity() {
|
public Optional<AppCompatActivity> getParentActivity() {
|
||||||
final ViewParent rootParent = binding.getRoot().getParent();
|
final ViewParent rootParent = binding.getRoot().getParent();
|
||||||
|
|
|
@ -8,7 +8,6 @@ import static org.schabi.newpipe.player.helper.PlayerHelper.retrievePopupLayoutP
|
||||||
import android.animation.Animator;
|
import android.animation.Animator;
|
||||||
import android.animation.AnimatorListenerAdapter;
|
import android.animation.AnimatorListenerAdapter;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
@ -61,6 +60,12 @@ public final class PopupPlayerUi extends VideoPlayerUi {
|
||||||
private WindowManager.LayoutParams popupLayoutParams; // null if player is not popup
|
private WindowManager.LayoutParams popupLayoutParams; // null if player is not popup
|
||||||
private final WindowManager windowManager;
|
private final WindowManager windowManager;
|
||||||
|
|
||||||
|
|
||||||
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
// Constructor, setup, destroy
|
||||||
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
//region Constructor, setup, destroy
|
||||||
|
|
||||||
public PopupPlayerUi(@NonNull final Player player,
|
public PopupPlayerUi(@NonNull final Player player,
|
||||||
@NonNull final PlayerBinding playerBinding) {
|
@NonNull final PlayerBinding playerBinding) {
|
||||||
super(player, playerBinding);
|
super(player, playerBinding);
|
||||||
|
@ -173,11 +178,14 @@ public final class PopupPlayerUi extends VideoPlayerUi {
|
||||||
super.destroy();
|
super.destroy();
|
||||||
removePopupFromView();
|
removePopupFromView();
|
||||||
}
|
}
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Broadcast receiver
|
// Broadcast receiver
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
//region Broadcast receiver
|
//region Broadcast receiver
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBroadcastReceived(final Intent intent) {
|
public void onBroadcastReceived(final Intent intent) {
|
||||||
super.onBroadcastReceived(intent);
|
super.onBroadcastReceived(intent);
|
||||||
|
@ -200,6 +208,11 @@ public final class PopupPlayerUi extends VideoPlayerUi {
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
// Popup position and size
|
||||||
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
//region Popup position and size
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if {@link #popupLayoutParams}' position is within a arbitrary boundary
|
* Check if {@link #popupLayoutParams}' position is within a arbitrary boundary
|
||||||
* that goes from (0, 0) to (screenWidth, screenHeight).
|
* that goes from (0, 0) to (screenWidth, screenHeight).
|
||||||
|
@ -272,16 +285,19 @@ public final class PopupPlayerUi extends VideoPlayerUi {
|
||||||
windowManager.updateViewLayout(binding.getRoot(), popupLayoutParams);
|
windowManager.updateViewLayout(binding.getRoot(), popupLayoutParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changePopupWindowFlags(final int flags) {
|
@Override
|
||||||
if (DEBUG) {
|
protected float calculateMaxEndScreenThumbnailHeight(@NonNull final Bitmap bitmap) {
|
||||||
Log.d(TAG, "changePopupWindowFlags() called with: flags = [" + flags + "]");
|
// no need for the end screen thumbnail to be resized on popup player: it's only needed
|
||||||
}
|
// for the main player so that it is enlarged correctly inside the fragment
|
||||||
|
return bitmap.getHeight();
|
||||||
if (!anyPopupViewIsNull()) {
|
|
||||||
popupLayoutParams.flags = flags;
|
|
||||||
windowManager.updateViewLayout(binding.getRoot(), popupLayoutParams);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
// Popup closing
|
||||||
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
//region Popup closing
|
||||||
|
|
||||||
public void closePopup() {
|
public void closePopup() {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
|
@ -351,23 +367,22 @@ public final class PopupPlayerUi extends VideoPlayerUi {
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
//endregion
|
||||||
|
|
||||||
@Override
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
protected float calculateMaxEndScreenThumbnailHeight(@NonNull final Bitmap bitmap) {
|
// Playback states
|
||||||
// no need for the end screen thumbnail to be resized on popup player: it's only needed
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
// for the main player so that it is enlarged correctly inside the fragment
|
//region Playback states
|
||||||
return bitmap.getHeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean popupHasParent() {
|
private void changePopupWindowFlags(final int flags) {
|
||||||
return binding != null
|
if (DEBUG) {
|
||||||
&& binding.getRoot().getLayoutParams() instanceof WindowManager.LayoutParams
|
Log.d(TAG, "changePopupWindowFlags() called with: flags = [" + flags + "]");
|
||||||
&& binding.getRoot().getParent() != null;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private boolean anyPopupViewIsNull() {
|
if (!anyPopupViewIsNull()) {
|
||||||
return popupLayoutParams == null || windowManager == null
|
popupLayoutParams.flags = flags;
|
||||||
|| binding.getRoot().getParent() == null;
|
windowManager.updateViewLayout(binding.getRoot(), popupLayoutParams);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -400,11 +415,14 @@ public final class PopupPlayerUi extends VideoPlayerUi {
|
||||||
playbackSpeedPopupMenu.show();
|
playbackSpeedPopupMenu.show();
|
||||||
isSomePopupMenuVisible = true;
|
isSomePopupMenuVisible = true;
|
||||||
}
|
}
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Gestures
|
// Gestures
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
//region Gestures
|
//region Gestures
|
||||||
|
|
||||||
private int distanceFromCloseButton(@NonNull final MotionEvent popupMotionEvent) {
|
private int distanceFromCloseButton(@NonNull final MotionEvent popupMotionEvent) {
|
||||||
final int closeOverlayButtonX = closeOverlayBinding.closeButton.getLeft()
|
final int closeOverlayButtonX = closeOverlayBinding.closeButton.getLeft()
|
||||||
+ closeOverlayBinding.closeButton.getWidth() / 2;
|
+ closeOverlayBinding.closeButton.getWidth() / 2;
|
||||||
|
@ -433,7 +451,19 @@ public final class PopupPlayerUi extends VideoPlayerUi {
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Getters
|
// Getters
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
//region Gestures
|
//region Getters
|
||||||
|
|
||||||
|
private boolean popupHasParent() {
|
||||||
|
return binding != null
|
||||||
|
&& binding.getRoot().getLayoutParams() instanceof WindowManager.LayoutParams
|
||||||
|
&& binding.getRoot().getParent() != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean anyPopupViewIsNull() {
|
||||||
|
return popupLayoutParams == null || windowManager == null
|
||||||
|
|| binding.getRoot().getParent() == null;
|
||||||
|
}
|
||||||
|
|
||||||
public PlayerPopupCloseOverlayBinding getCloseOverlayBinding() {
|
public PlayerPopupCloseOverlayBinding getCloseOverlayBinding() {
|
||||||
return closeOverlayBinding;
|
return closeOverlayBinding;
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,6 +135,12 @@ public abstract class VideoPlayerUi extends PlayerUi
|
||||||
@NonNull private final SeekbarPreviewThumbnailHolder seekbarPreviewThumbnailHolder =
|
@NonNull private final SeekbarPreviewThumbnailHolder seekbarPreviewThumbnailHolder =
|
||||||
new SeekbarPreviewThumbnailHolder();
|
new SeekbarPreviewThumbnailHolder();
|
||||||
|
|
||||||
|
|
||||||
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
// Constructor, setup, destroy
|
||||||
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
//region Constructor, setup, destroy
|
||||||
|
|
||||||
public VideoPlayerUi(@NonNull final Player player,
|
public VideoPlayerUi(@NonNull final Player player,
|
||||||
@NonNull final PlayerBinding playerBinding) {
|
@NonNull final PlayerBinding playerBinding) {
|
||||||
super(player);
|
super(player);
|
||||||
|
@ -142,11 +148,6 @@ public abstract class VideoPlayerUi extends PlayerUi
|
||||||
setupFromView();
|
setupFromView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
|
||||||
// Setup
|
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
|
||||||
//region Setup
|
|
||||||
public void setupFromView() {
|
public void setupFromView() {
|
||||||
initViews();
|
initViews();
|
||||||
initListeners();
|
initListeners();
|
||||||
|
@ -414,6 +415,7 @@ public abstract class VideoPlayerUi extends PlayerUi
|
||||||
// Broadcast receiver
|
// Broadcast receiver
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
//region Broadcast receiver
|
//region Broadcast receiver
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBroadcastReceived(final Intent intent) {
|
public void onBroadcastReceived(final Intent intent) {
|
||||||
super.onBroadcastReceived(intent);
|
super.onBroadcastReceived(intent);
|
||||||
|
@ -433,6 +435,7 @@ public abstract class VideoPlayerUi extends PlayerUi
|
||||||
// Thumbnail
|
// Thumbnail
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
//region Thumbnail
|
//region Thumbnail
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scale the player audio / end screen thumbnail down if necessary.
|
* Scale the player audio / end screen thumbnail down if necessary.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -481,6 +484,7 @@ public abstract class VideoPlayerUi extends PlayerUi
|
||||||
// Progress loop and updates
|
// Progress loop and updates
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
//region Progress loop and updates
|
//region Progress loop and updates
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdateProgress(final int currentProgress,
|
public void onUpdateProgress(final int currentProgress,
|
||||||
final int duration,
|
final int duration,
|
||||||
|
@ -744,6 +748,7 @@ public abstract class VideoPlayerUi extends PlayerUi
|
||||||
// Playback states
|
// Playback states
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
//region Playback states
|
//region Playback states
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPrepared() {
|
public void onPrepared() {
|
||||||
super.onPrepared();
|
super.onPrepared();
|
||||||
|
@ -885,7 +890,8 @@ public abstract class VideoPlayerUi extends PlayerUi
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Repeat, shuffle, mute
|
// Repeat, shuffle, mute
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
//region Repeat and shuffle
|
//region Repeat, shuffle, mute
|
||||||
|
|
||||||
public void onRepeatClicked() {
|
public void onRepeatClicked() {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "onRepeatClicked() called");
|
Log.d(TAG, "onRepeatClicked() called");
|
||||||
|
@ -945,52 +951,9 @@ public abstract class VideoPlayerUi extends PlayerUi
|
||||||
|
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// ExoPlayer listeners (that didn't fit in other categories)
|
// Other player listeners
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
//region ExoPlayer listeners (that didn't fit in other categories)
|
//region Other player listeners
|
||||||
@Override
|
|
||||||
public void onTextTracksChanged(@NonNull final Tracks currentTracks) {
|
|
||||||
super.onTextTracksChanged(currentTracks);
|
|
||||||
|
|
||||||
final boolean trackTypeTextSupported = !currentTracks.containsType(C.TRACK_TYPE_TEXT)
|
|
||||||
|| currentTracks.isTypeSupported(C.TRACK_TYPE_TEXT, false);
|
|
||||||
if (getPlayer().getTrackSelector().getCurrentMappedTrackInfo() == null
|
|
||||||
|| !trackTypeTextSupported) {
|
|
||||||
binding.captionTextView.setVisibility(View.GONE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extract all loaded languages
|
|
||||||
final List<Tracks.Group> textTracks = currentTracks
|
|
||||||
.getGroups()
|
|
||||||
.stream()
|
|
||||||
.filter(trackGroupInfo -> C.TRACK_TYPE_TEXT == trackGroupInfo.getType())
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
final List<String> availableLanguages = textTracks.stream()
|
|
||||||
.map(Tracks.Group::getMediaTrackGroup)
|
|
||||||
.filter(textTrack -> textTrack.length > 0)
|
|
||||||
.map(textTrack -> textTrack.getFormat(0).language)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
// Find selected text track
|
|
||||||
final Optional<Format> selectedTracks = textTracks.stream()
|
|
||||||
.filter(Tracks.Group::isSelected)
|
|
||||||
.filter(info -> info.getMediaTrackGroup().length >= 1)
|
|
||||||
.map(info -> info.getMediaTrackGroup().getFormat(0))
|
|
||||||
.findFirst();
|
|
||||||
|
|
||||||
// Build UI
|
|
||||||
buildCaptionMenu(availableLanguages);
|
|
||||||
//noinspection SimplifyOptionalCallChains
|
|
||||||
if (player.getTrackSelector().getParameters().getRendererDisabled(
|
|
||||||
player.getCaptionRendererIndex()) || !selectedTracks.isPresent()) {
|
|
||||||
binding.captionTextView.setText(R.string.caption_none);
|
|
||||||
} else {
|
|
||||||
binding.captionTextView.setText(selectedTracks.get().language);
|
|
||||||
}
|
|
||||||
binding.captionTextView.setVisibility(
|
|
||||||
availableLanguages.isEmpty() ? View.GONE : View.VISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlaybackParametersChanged(@NonNull final PlaybackParameters playbackParameters) {
|
public void onPlaybackParametersChanged(@NonNull final PlaybackParameters playbackParameters) {
|
||||||
|
@ -1004,12 +967,6 @@ public abstract class VideoPlayerUi extends PlayerUi
|
||||||
//TODO check if this causes black screen when switching to fullscreen
|
//TODO check if this causes black screen when switching to fullscreen
|
||||||
animate(binding.surfaceForeground, false, DEFAULT_CONTROLS_DURATION);
|
animate(binding.surfaceForeground, false, DEFAULT_CONTROLS_DURATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCues(@NonNull List<Cue> cues) {
|
|
||||||
super.onCues(cues);
|
|
||||||
binding.subtitleView.setCues(cues);
|
|
||||||
}
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
@ -1017,6 +974,7 @@ public abstract class VideoPlayerUi extends PlayerUi
|
||||||
// Metadata & stream related views
|
// Metadata & stream related views
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
//region Metadata & stream related views
|
//region Metadata & stream related views
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMetadataChanged(@NonNull final StreamInfo info) {
|
public void onMetadataChanged(@NonNull final StreamInfo info) {
|
||||||
super.onMetadataChanged(info);
|
super.onMetadataChanged(info);
|
||||||
|
@ -1092,6 +1050,7 @@ public abstract class VideoPlayerUi extends PlayerUi
|
||||||
// Popup menus ("popup" means that they pop up, not that they belong to the popup player)
|
// Popup menus ("popup" means that they pop up, not that they belong to the popup player)
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
//region Popup menus ("popup" means that they pop up, not that they belong to the popup player)
|
//region Popup menus ("popup" means that they pop up, not that they belong to the popup player)
|
||||||
|
|
||||||
private void buildQualityMenu() {
|
private void buildQualityMenu() {
|
||||||
if (qualityPopupMenu == null) {
|
if (qualityPopupMenu == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -1315,6 +1274,57 @@ public abstract class VideoPlayerUi extends PlayerUi
|
||||||
// Captions (text tracks)
|
// Captions (text tracks)
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
//region Captions (text tracks)
|
//region Captions (text tracks)
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTextTracksChanged(@NonNull final Tracks currentTracks) {
|
||||||
|
super.onTextTracksChanged(currentTracks);
|
||||||
|
|
||||||
|
final boolean trackTypeTextSupported = !currentTracks.containsType(C.TRACK_TYPE_TEXT)
|
||||||
|
|| currentTracks.isTypeSupported(C.TRACK_TYPE_TEXT, false);
|
||||||
|
if (getPlayer().getTrackSelector().getCurrentMappedTrackInfo() == null
|
||||||
|
|| !trackTypeTextSupported) {
|
||||||
|
binding.captionTextView.setVisibility(View.GONE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract all loaded languages
|
||||||
|
final List<Tracks.Group> textTracks = currentTracks
|
||||||
|
.getGroups()
|
||||||
|
.stream()
|
||||||
|
.filter(trackGroupInfo -> C.TRACK_TYPE_TEXT == trackGroupInfo.getType())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
final List<String> availableLanguages = textTracks.stream()
|
||||||
|
.map(Tracks.Group::getMediaTrackGroup)
|
||||||
|
.filter(textTrack -> textTrack.length > 0)
|
||||||
|
.map(textTrack -> textTrack.getFormat(0).language)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
// Find selected text track
|
||||||
|
final Optional<Format> selectedTracks = textTracks.stream()
|
||||||
|
.filter(Tracks.Group::isSelected)
|
||||||
|
.filter(info -> info.getMediaTrackGroup().length >= 1)
|
||||||
|
.map(info -> info.getMediaTrackGroup().getFormat(0))
|
||||||
|
.findFirst();
|
||||||
|
|
||||||
|
// Build UI
|
||||||
|
buildCaptionMenu(availableLanguages);
|
||||||
|
//noinspection SimplifyOptionalCallChains
|
||||||
|
if (player.getTrackSelector().getParameters().getRendererDisabled(
|
||||||
|
player.getCaptionRendererIndex()) || !selectedTracks.isPresent()) {
|
||||||
|
binding.captionTextView.setText(R.string.caption_none);
|
||||||
|
} else {
|
||||||
|
binding.captionTextView.setText(selectedTracks.get().language);
|
||||||
|
}
|
||||||
|
binding.captionTextView.setVisibility(
|
||||||
|
availableLanguages.isEmpty() ? View.GONE : View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCues(@NonNull List<Cue> cues) {
|
||||||
|
super.onCues(cues);
|
||||||
|
binding.subtitleView.setCues(cues);
|
||||||
|
}
|
||||||
|
|
||||||
private void setupSubtitleView() {
|
private void setupSubtitleView() {
|
||||||
setupSubtitleView(PlayerHelper.getCaptionScale(context));
|
setupSubtitleView(PlayerHelper.getCaptionScale(context));
|
||||||
final CaptionStyleCompat captionStyle = PlayerHelper.getCaptionStyle(context);
|
final CaptionStyleCompat captionStyle = PlayerHelper.getCaptionStyle(context);
|
||||||
|
@ -1330,6 +1340,7 @@ public abstract class VideoPlayerUi extends PlayerUi
|
||||||
// Click listeners
|
// Click listeners
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
//region Click listeners
|
//region Click listeners
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(final View v) {
|
public void onClick(final View v) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
|
@ -1493,9 +1504,10 @@ public abstract class VideoPlayerUi extends PlayerUi
|
||||||
|
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Video size, resize, orientation, fullscreen
|
// Video size
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
//region Video size, resize, orientation, fullscreen
|
//region Video size
|
||||||
|
|
||||||
protected void setResizeMode(@AspectRatioFrameLayout.ResizeMode final int resizeMode) {
|
protected void setResizeMode(@AspectRatioFrameLayout.ResizeMode final int resizeMode) {
|
||||||
binding.surfaceView.setResizeMode(resizeMode);
|
binding.surfaceView.setResizeMode(resizeMode);
|
||||||
binding.resizeTextView.setText(PlayerHelper.resizeTypeOf(context, resizeMode));
|
binding.resizeTextView.setText(PlayerHelper.resizeTypeOf(context, resizeMode));
|
||||||
|
@ -1569,6 +1581,7 @@ public abstract class VideoPlayerUi extends PlayerUi
|
||||||
// Getters
|
// Getters
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
//region Getters
|
//region Getters
|
||||||
|
|
||||||
public PlayerBinding getBinding() {
|
public PlayerBinding getBinding() {
|
||||||
return binding;
|
return binding;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue