1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-24 00:50:32 +00:00

Merge pull request #5253 from Isira-Seneviratne/Use_view_binding_in_VideoPlayer

Use view binding in VideoPlayer.
This commit is contained in:
Stypox 2021-01-13 22:07:19 +01:00 committed by GitHub
commit e2ea217bc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 411 additions and 572 deletions

View File

@ -225,13 +225,6 @@ public abstract class BasePlayer implements
this.renderFactory = new DefaultRenderersFactory(context); this.renderFactory = new DefaultRenderersFactory(context);
} }
public void setup() {
if (simpleExoPlayer == null) {
initPlayer(true);
}
initListeners();
}
public void initPlayer(final boolean playOnReady) { public void initPlayer(final boolean playOnReady) {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "initPlayer() called with: playOnReady = [" + playOnReady + "]"); Log.d(TAG, "initPlayer() called with: playOnReady = [" + playOnReady + "]");

View File

@ -26,6 +26,7 @@ import android.os.Binder;
import android.os.IBinder; import android.os.IBinder;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.WindowManager; import android.view.WindowManager;
@ -33,8 +34,8 @@ import android.view.WindowManager;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import org.schabi.newpipe.databinding.PlayerBinding;
import org.schabi.newpipe.App; import org.schabi.newpipe.App;
import org.schabi.newpipe.R;
import org.schabi.newpipe.util.ThemeHelper; import org.schabi.newpipe.util.ThemeHelper;
import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;
@ -102,10 +103,10 @@ public final class MainPlayer extends Service {
} }
private void createView() { private void createView() {
final View layout = View.inflate(this, R.layout.player, null); final PlayerBinding binding = PlayerBinding.inflate(LayoutInflater.from(this));
playerImpl = new VideoPlayerImpl(this); playerImpl = new VideoPlayerImpl(this);
playerImpl.setup(layout); playerImpl.setup(binding);
playerImpl.shouldUpdateOnProgress = true; playerImpl.shouldUpdateOnProgress = true;
NotificationUtil.getInstance().createNotificationAndStartForeground(playerImpl, this); NotificationUtil.getInstance().createNotificationAndStartForeground(playerImpl, this);

View File

@ -33,21 +33,18 @@ import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter; import android.graphics.PorterDuffColorFilter;
import android.os.Build; import android.os.Build;
import android.os.Handler; import android.os.Handler;
import androidx.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupMenu; import android.widget.PopupMenu;
import android.widget.ProgressBar;
import android.widget.SeekBar; import android.widget.SeekBar;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.content.res.AppCompatResources; import androidx.appcompat.content.res.AppCompatResources;
import androidx.preference.PreferenceManager;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.PlaybackParameters; import com.google.android.exoplayer2.PlaybackParameters;
@ -62,6 +59,7 @@ import com.google.android.exoplayer2.ui.SubtitleView;
import com.google.android.exoplayer2.video.VideoListener; import com.google.android.exoplayer2.video.VideoListener;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.databinding.PlayerBinding;
import org.schabi.newpipe.extractor.MediaFormat; import org.schabi.newpipe.extractor.MediaFormat;
import org.schabi.newpipe.extractor.stream.StreamInfo; import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.extractor.stream.VideoStream; import org.schabi.newpipe.extractor.stream.VideoStream;
@ -84,7 +82,7 @@ import static org.schabi.newpipe.util.AnimationUtils.animateView;
* *
* @author mauriciocolli * @author mauriciocolli
*/ */
@SuppressWarnings({"WeakerAccess", "unused"}) @SuppressWarnings({"WeakerAccess"})
public abstract class VideoPlayer extends BasePlayer public abstract class VideoPlayer extends BasePlayer
implements VideoListener, implements VideoListener,
SeekBar.OnSeekBarChangeListener, SeekBar.OnSeekBarChangeListener,
@ -117,34 +115,11 @@ public abstract class VideoPlayer extends BasePlayer
// Views // Views
//////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////*/
private View rootView; protected PlayerBinding binding;
private ExpandableSurfaceView surfaceView; protected SeekBar playbackSeekBar;
private View surfaceForeground; protected TextView qualityTextView;
protected TextView playbackSpeed;
private View loadingPanel;
private ImageView endScreen;
private ImageView controlAnimationView;
private View controlsRoot;
private TextView currentDisplaySeek;
private View playerTopShadow;
private View playerBottomShadow;
private View bottomControlsRoot;
private SeekBar playbackSeekBar;
private TextView playbackCurrentTime;
private TextView playbackEndTime;
private TextView playbackLiveSync;
private TextView playbackSpeedTextView;
private LinearLayout topControlsRoot;
private TextView qualityTextView;
private SubtitleView subtitleView;
private TextView resizeView;
private TextView captionTextView;
private ValueAnimator controlViewAnimator; private ValueAnimator controlViewAnimator;
private final Handler controlsVisibilityHandler = new Handler(); private final Handler controlsVisibilityHandler = new Handler();
@ -162,7 +137,7 @@ public abstract class VideoPlayer extends BasePlayer
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
public VideoPlayer(final String debugTag, final Context context) { protected VideoPlayer(final String debugTag, final Context context) {
super(context); super(context);
this.TAG = debugTag; this.TAG = debugTag;
this.resolver = new VideoPlaybackResolver(context, dataSource, getQualityResolver()); this.resolver = new VideoPlaybackResolver(context, dataSource, getQualityResolver());
@ -178,54 +153,37 @@ public abstract class VideoPlayer extends BasePlayer
return false; return false;
} }
public void setup(final View view) { public void setup(@NonNull final PlayerBinding playerBinding) {
initViews(view); initViews(playerBinding);
setup(); if (simpleExoPlayer == null) {
initPlayer(true);
}
initListeners();
} }
public void initViews(final View view) { public void initViews(@NonNull final PlayerBinding playerBinding) {
this.rootView = view; binding = playerBinding;
this.surfaceView = view.findViewById(R.id.surfaceView); playbackSeekBar = (SeekBar) binding.playbackSeekBar;
this.surfaceForeground = view.findViewById(R.id.surfaceForeground); qualityTextView = (TextView) binding.qualityTextView;
this.loadingPanel = view.findViewById(R.id.loading_panel); playbackSpeed = (TextView) binding.playbackSpeed;
this.endScreen = view.findViewById(R.id.endScreen);
this.controlAnimationView = view.findViewById(R.id.controlAnimationView);
this.controlsRoot = view.findViewById(R.id.playbackControlRoot);
this.currentDisplaySeek = view.findViewById(R.id.currentDisplaySeek);
this.playerTopShadow = view.findViewById(R.id.playerTopShadow);
this.playerBottomShadow = view.findViewById(R.id.playerBottomShadow);
this.playbackSeekBar = view.findViewById(R.id.playbackSeekBar);
this.playbackCurrentTime = view.findViewById(R.id.playbackCurrentTime);
this.playbackEndTime = view.findViewById(R.id.playbackEndTime);
this.playbackLiveSync = view.findViewById(R.id.playbackLiveSync);
this.playbackSpeedTextView = view.findViewById(R.id.playbackSpeed);
this.bottomControlsRoot = view.findViewById(R.id.bottomControls);
this.topControlsRoot = view.findViewById(R.id.topControls);
this.qualityTextView = view.findViewById(R.id.qualityTextView);
this.subtitleView = view.findViewById(R.id.subtitleView);
final float captionScale = PlayerHelper.getCaptionScale(context); final float captionScale = PlayerHelper.getCaptionScale(context);
final CaptionStyleCompat captionStyle = PlayerHelper.getCaptionStyle(context); final CaptionStyleCompat captionStyle = PlayerHelper.getCaptionStyle(context);
setupSubtitleView(subtitleView, captionScale, captionStyle); setupSubtitleView(binding.subtitleView, captionScale, captionStyle);
this.resizeView = view.findViewById(R.id.resizeTextView); ((TextView) binding.resizeTextView).setText(PlayerHelper.resizeTypeOf(context,
resizeView.setText(PlayerHelper binding.surfaceView.getResizeMode()));
.resizeTypeOf(context, getSurfaceView().getResizeMode()));
this.captionTextView = view.findViewById(R.id.captionTextView); playbackSeekBar.getThumb().setColorFilter(new PorterDuffColorFilter(Color.RED,
PorterDuff.Mode.SRC_IN));
playbackSeekBar.getProgressDrawable().setColorFilter(new PorterDuffColorFilter(Color.RED,
PorterDuff.Mode.MULTIPLY));
playbackSeekBar.getThumb() qualityPopupMenu = new PopupMenu(context, qualityTextView);
.setColorFilter(new PorterDuffColorFilter(Color.RED, PorterDuff.Mode.SRC_IN)); playbackSpeedPopupMenu = new PopupMenu(context, playbackSpeed);
this.playbackSeekBar.getProgressDrawable() captionPopupMenu = new PopupMenu(context, binding.captionTextView);
.setColorFilter(new PorterDuffColorFilter(Color.RED, PorterDuff.Mode.MULTIPLY));
this.qualityPopupMenu = new PopupMenu(context, qualityTextView); binding.progressBarLoadingPanel.getIndeterminateDrawable()
this.playbackSpeedPopupMenu = new PopupMenu(context, playbackSpeedTextView);
this.captionPopupMenu = new PopupMenu(context, captionTextView);
((ProgressBar) this.loadingPanel.findViewById(R.id.progressBarLoadingPanel))
.getIndeterminateDrawable()
.setColorFilter(new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.MULTIPLY)); .setColorFilter(new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.MULTIPLY));
} }
@ -235,11 +193,11 @@ public abstract class VideoPlayer extends BasePlayer
@Override @Override
public void initListeners() { public void initListeners() {
playbackSeekBar.setOnSeekBarChangeListener(this); playbackSeekBar.setOnSeekBarChangeListener(this);
playbackSpeedTextView.setOnClickListener(this); binding.playbackSpeed.setOnClickListener(this);
qualityTextView.setOnClickListener(this); binding.qualityTextView.setOnClickListener(this);
captionTextView.setOnClickListener(this); binding.captionTextView.setOnClickListener(this);
resizeView.setOnClickListener(this); binding.resizeTextView.setOnClickListener(this);
playbackLiveSync.setOnClickListener(this); binding.playbackLiveSync.setOnClickListener(this);
} }
@Override @Override
@ -247,11 +205,11 @@ public abstract class VideoPlayer extends BasePlayer
super.initPlayer(playOnReady); super.initPlayer(playOnReady);
// Setup video view // Setup video view
simpleExoPlayer.setVideoSurfaceView(surfaceView); simpleExoPlayer.setVideoSurfaceView(binding.surfaceView);
simpleExoPlayer.addVideoListener(this); simpleExoPlayer.addVideoListener(this);
// Setup subtitle view // Setup subtitle view
simpleExoPlayer.addTextOutput(cues -> subtitleView.onCues(cues)); simpleExoPlayer.addTextOutput(binding.subtitleView);
// Setup audio session with onboard equalizer // Setup audio session with onboard equalizer
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
@ -305,7 +263,7 @@ public abstract class VideoPlayer extends BasePlayer
playbackSpeedPopupMenu.getMenu().add(playbackSpeedPopupMenuGroupId, i, Menu.NONE, playbackSpeedPopupMenu.getMenu().add(playbackSpeedPopupMenuGroupId, i, Menu.NONE,
formatSpeed(PLAYBACK_SPEEDS[i])); formatSpeed(PLAYBACK_SPEEDS[i]));
} }
playbackSpeedTextView.setText(formatSpeed(getPlaybackSpeed())); playbackSpeed.setText(formatSpeed(getPlaybackSpeed()));
playbackSpeedPopupMenu.setOnMenuItemClickListener(this); playbackSpeedPopupMenu.setOnMenuItemClickListener(this);
playbackSpeedPopupMenu.setOnDismissListener(this); playbackSpeedPopupMenu.setOnDismissListener(this);
} }
@ -385,29 +343,29 @@ public abstract class VideoPlayer extends BasePlayer
final MediaSourceTag tag = getCurrentMetadata(); final MediaSourceTag tag = getCurrentMetadata();
final StreamInfo metadata = tag.getMetadata(); final StreamInfo metadata = tag.getMetadata();
qualityTextView.setVisibility(View.GONE); binding.qualityTextView.setVisibility(View.GONE);
playbackSpeedTextView.setVisibility(View.GONE); binding.playbackSpeed.setVisibility(View.GONE);
playbackEndTime.setVisibility(View.GONE); binding.playbackEndTime.setVisibility(View.GONE);
playbackLiveSync.setVisibility(View.GONE); binding.playbackLiveSync.setVisibility(View.GONE);
switch (metadata.getStreamType()) { switch (metadata.getStreamType()) {
case AUDIO_STREAM: case AUDIO_STREAM:
surfaceView.setVisibility(View.GONE); binding.surfaceView.setVisibility(View.GONE);
endScreen.setVisibility(View.VISIBLE); binding.endScreen.setVisibility(View.VISIBLE);
playbackEndTime.setVisibility(View.VISIBLE); binding.playbackEndTime.setVisibility(View.VISIBLE);
break; break;
case AUDIO_LIVE_STREAM: case AUDIO_LIVE_STREAM:
surfaceView.setVisibility(View.GONE); binding.surfaceView.setVisibility(View.GONE);
endScreen.setVisibility(View.VISIBLE); binding.endScreen.setVisibility(View.VISIBLE);
playbackLiveSync.setVisibility(View.VISIBLE); binding.playbackLiveSync.setVisibility(View.VISIBLE);
break; break;
case LIVE_STREAM: case LIVE_STREAM:
surfaceView.setVisibility(View.VISIBLE); binding.surfaceView.setVisibility(View.VISIBLE);
endScreen.setVisibility(View.GONE); binding.endScreen.setVisibility(View.GONE);
playbackLiveSync.setVisibility(View.VISIBLE); binding.playbackLiveSync.setVisibility(View.VISIBLE);
break; break;
case VIDEO_STREAM: case VIDEO_STREAM:
@ -420,16 +378,16 @@ public abstract class VideoPlayer extends BasePlayer
selectedStreamIndex = tag.getSelectedVideoStreamIndex(); selectedStreamIndex = tag.getSelectedVideoStreamIndex();
buildQualityMenu(); buildQualityMenu();
qualityTextView.setVisibility(View.VISIBLE); binding.qualityTextView.setVisibility(View.VISIBLE);
surfaceView.setVisibility(View.VISIBLE); binding.surfaceView.setVisibility(View.VISIBLE);
default: default:
endScreen.setVisibility(View.GONE); binding.endScreen.setVisibility(View.GONE);
playbackEndTime.setVisibility(View.VISIBLE); binding.playbackEndTime.setVisibility(View.VISIBLE);
break; break;
} }
buildPlaybackSpeedMenu(); buildPlaybackSpeedMenu();
playbackSpeedTextView.setVisibility(View.VISIBLE); binding.playbackSpeed.setVisibility(View.VISIBLE);
} }
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
@ -438,6 +396,7 @@ public abstract class VideoPlayer extends BasePlayer
protected abstract VideoPlaybackResolver.QualityResolver getQualityResolver(); protected abstract VideoPlaybackResolver.QualityResolver getQualityResolver();
@Override
protected void onMetadataChanged(@NonNull final MediaSourceTag tag) { protected void onMetadataChanged(@NonNull final MediaSourceTag tag) {
super.onMetadataChanged(tag); super.onMetadataChanged(tag);
updateStreamRelatedViews(); updateStreamRelatedViews();
@ -458,15 +417,15 @@ public abstract class VideoPlayer extends BasePlayer
super.onBlocked(); super.onBlocked();
controlsVisibilityHandler.removeCallbacksAndMessages(null); controlsVisibilityHandler.removeCallbacksAndMessages(null);
animateView(controlsRoot, false, DEFAULT_CONTROLS_DURATION); animateView(binding.playbackControlRoot, false, DEFAULT_CONTROLS_DURATION);
playbackSeekBar.setEnabled(false); playbackSeekBar.setEnabled(false);
playbackSeekBar.getThumb() playbackSeekBar.getThumb().setColorFilter(new PorterDuffColorFilter(Color.RED,
.setColorFilter(new PorterDuffColorFilter(Color.RED, PorterDuff.Mode.SRC_IN)); PorterDuff.Mode.SRC_IN));
loadingPanel.setBackgroundColor(Color.BLACK); binding.loadingPanel.setBackgroundColor(Color.BLACK);
animateView(loadingPanel, true, 0); animateView(binding.loadingPanel, true, 0);
animateView(surfaceForeground, true, 100); animateView(binding.surfaceForeground, true, 100);
} }
@Override @Override
@ -478,12 +437,13 @@ public abstract class VideoPlayer extends BasePlayer
showAndAnimateControl(-1, true); showAndAnimateControl(-1, true);
playbackSeekBar.setEnabled(true); playbackSeekBar.setEnabled(true);
playbackSeekBar.getThumb() playbackSeekBar.getThumb().setColorFilter(new PorterDuffColorFilter(Color.RED,
.setColorFilter(new PorterDuffColorFilter(Color.RED, PorterDuff.Mode.SRC_IN)); PorterDuff.Mode.SRC_IN));
loadingPanel.setVisibility(View.GONE); binding.loadingPanel.setVisibility(View.GONE);
animateView(currentDisplaySeek, AnimationUtils.Type.SCALE_AND_ALPHA, false, 200); animateView(binding.currentDisplaySeek, AnimationUtils.Type.SCALE_AND_ALPHA, false,
200);
} }
@Override @Override
@ -491,7 +451,7 @@ public abstract class VideoPlayer extends BasePlayer
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "onBuffering() called"); Log.d(TAG, "onBuffering() called");
} }
loadingPanel.setBackgroundColor(Color.TRANSPARENT); binding.loadingPanel.setBackgroundColor(Color.TRANSPARENT);
} }
@Override @Override
@ -500,7 +460,7 @@ public abstract class VideoPlayer extends BasePlayer
Log.d(TAG, "onPaused() called"); Log.d(TAG, "onPaused() called");
} }
showControls(400); showControls(400);
loadingPanel.setVisibility(View.GONE); binding.loadingPanel.setVisibility(View.GONE);
} }
@Override @Override
@ -516,10 +476,11 @@ public abstract class VideoPlayer extends BasePlayer
super.onCompleted(); super.onCompleted();
showControls(500); showControls(500);
animateView(currentDisplaySeek, AnimationUtils.Type.SCALE_AND_ALPHA, false, 200); animateView(binding.currentDisplaySeek, AnimationUtils.Type.SCALE_AND_ALPHA, false,
loadingPanel.setVisibility(View.GONE); 200);
binding.loadingPanel.setVisibility(View.GONE);
animateView(surfaceForeground, true, 100); animateView(binding.surfaceForeground, true, 100);
} }
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
@ -527,16 +488,16 @@ public abstract class VideoPlayer extends BasePlayer
//////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////*/
@Override @Override
public void onTracksChanged(final TrackGroupArray trackGroups, public void onTracksChanged(@NonNull final TrackGroupArray trackGroups,
final TrackSelectionArray trackSelections) { @NonNull final TrackSelectionArray trackSelections) {
super.onTracksChanged(trackGroups, trackSelections); super.onTracksChanged(trackGroups, trackSelections);
onTextTrackUpdate(); onTextTrackUpdate();
} }
@Override @Override
public void onPlaybackParametersChanged(final PlaybackParameters playbackParameters) { public void onPlaybackParametersChanged(@NonNull final PlaybackParameters playbackParameters) {
super.onPlaybackParametersChanged(playbackParameters); super.onPlaybackParametersChanged(playbackParameters);
playbackSpeedTextView.setText(formatSpeed(playbackParameters.speed)); playbackSpeed.setText(formatSpeed(playbackParameters.speed));
} }
@Override @Override
@ -550,12 +511,12 @@ public abstract class VideoPlayer extends BasePlayer
+ "unappliedRotationDegrees = [" + unappliedRotationDegrees + "], " + "unappliedRotationDegrees = [" + unappliedRotationDegrees + "], "
+ "pixelWidthHeightRatio = [" + pixelWidthHeightRatio + "]"); + "pixelWidthHeightRatio = [" + pixelWidthHeightRatio + "]");
} }
getSurfaceView().setAspectRatio(((float) width) / height); binding.surfaceView.setAspectRatio(((float) width) / height);
} }
@Override @Override
public void onRenderedFirstFrame() { public void onRenderedFirstFrame() {
animateView(surfaceForeground, false, 100); animateView(binding.surfaceForeground, false, 100);
} }
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
@ -565,12 +526,12 @@ public abstract class VideoPlayer extends BasePlayer
private void onTextTrackUpdate() { private void onTextTrackUpdate() {
final int textRenderer = getRendererIndex(C.TRACK_TYPE_TEXT); final int textRenderer = getRendererIndex(C.TRACK_TYPE_TEXT);
if (captionTextView == null) { if (binding == null) {
return; return;
} }
if (trackSelector.getCurrentMappedTrackInfo() == null if (trackSelector.getCurrentMappedTrackInfo() == null
|| textRenderer == RENDERER_UNAVAILABLE) { || textRenderer == RENDERER_UNAVAILABLE) {
captionTextView.setVisibility(View.GONE); binding.captionTextView.setVisibility(View.GONE);
return; return;
} }
@ -593,11 +554,12 @@ public abstract class VideoPlayer extends BasePlayer
if (trackSelector.getParameters().getRendererDisabled(textRenderer) if (trackSelector.getParameters().getRendererDisabled(textRenderer)
|| preferredLanguage == null || (!availableLanguages.contains(preferredLanguage) || preferredLanguage == null || (!availableLanguages.contains(preferredLanguage)
&& !containsCaseInsensitive(availableLanguages, preferredLanguage))) { && !containsCaseInsensitive(availableLanguages, preferredLanguage))) {
captionTextView.setText(R.string.caption_none); binding.captionTextView.setText(R.string.caption_none);
} else { } else {
captionTextView.setText(preferredLanguage); binding.captionTextView.setText(preferredLanguage);
} }
captionTextView.setVisibility(availableLanguages.isEmpty() ? View.GONE : View.VISIBLE); binding.captionTextView.setVisibility(availableLanguages.isEmpty() ? View.GONE
: View.VISIBLE);
} }
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
@ -611,8 +573,8 @@ public abstract class VideoPlayer extends BasePlayer
} }
playbackSeekBar.setMax((int) simpleExoPlayer.getDuration()); playbackSeekBar.setMax((int) simpleExoPlayer.getDuration());
playbackEndTime.setText(getTimeString((int) simpleExoPlayer.getDuration())); binding.playbackEndTime.setText(getTimeString((int) simpleExoPlayer.getDuration()));
playbackSpeedTextView.setText(formatSpeed(getPlaybackSpeed())); playbackSpeed.setText(formatSpeed(getPlaybackSpeed()));
super.onPrepared(playWhenReady); super.onPrepared(playWhenReady);
} }
@ -620,8 +582,8 @@ public abstract class VideoPlayer extends BasePlayer
@Override @Override
public void destroy() { public void destroy() {
super.destroy(); super.destroy();
if (endScreen != null) { if (binding != null) {
endScreen.setImageBitmap(null); binding.endScreen.setImageBitmap(null);
} }
} }
@ -633,14 +595,14 @@ public abstract class VideoPlayer extends BasePlayer
} }
if (duration != playbackSeekBar.getMax()) { if (duration != playbackSeekBar.getMax()) {
playbackEndTime.setText(getTimeString(duration)); binding.playbackEndTime.setText(getTimeString(duration));
playbackSeekBar.setMax(duration); playbackSeekBar.setMax(duration);
} }
if (currentState != STATE_PAUSED) { if (currentState != STATE_PAUSED) {
if (currentState != STATE_PAUSED_SEEK) { if (currentState != STATE_PAUSED_SEEK) {
playbackSeekBar.setProgress(currentProgress); playbackSeekBar.setProgress(currentProgress);
} }
playbackCurrentTime.setText(getTimeString(currentProgress)); binding.playbackCurrentTime.setText(getTimeString(currentProgress));
} }
if (simpleExoPlayer.isLoading() || bufferPercent > 90) { if (simpleExoPlayer.isLoading() || bufferPercent > 90) {
playbackSeekBar.setSecondaryProgress( playbackSeekBar.setSecondaryProgress(
@ -652,7 +614,7 @@ public abstract class VideoPlayer extends BasePlayer
+ "currentProgress = [" + currentProgress + "], " + "currentProgress = [" + currentProgress + "], "
+ "duration = [" + duration + "], bufferPercent = [" + bufferPercent + "]"); + "duration = [" + duration + "], bufferPercent = [" + bufferPercent + "]");
} }
playbackLiveSync.setClickable(!isLiveEdge()); binding.playbackLiveSync.setClickable(!isLiveEdge());
} }
@Override @Override
@ -660,7 +622,7 @@ public abstract class VideoPlayer extends BasePlayer
final Bitmap loadedImage) { final Bitmap loadedImage) {
super.onLoadingComplete(imageUri, view, loadedImage); super.onLoadingComplete(imageUri, view, loadedImage);
if (loadedImage != null) { if (loadedImage != null) {
endScreen.setImageBitmap(loadedImage); binding.endScreen.setImageBitmap(loadedImage);
} }
} }
@ -689,15 +651,15 @@ public abstract class VideoPlayer extends BasePlayer
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "onClick() called with: v = [" + v + "]"); Log.d(TAG, "onClick() called with: v = [" + v + "]");
} }
if (v.getId() == qualityTextView.getId()) { if (v.getId() == binding.qualityTextView.getId()) {
onQualitySelectorClicked(); onQualitySelectorClicked();
} else if (v.getId() == playbackSpeedTextView.getId()) { } else if (v.getId() == binding.playbackSpeed.getId()) {
onPlaybackSpeedClicked(); onPlaybackSpeedClicked();
} else if (v.getId() == resizeView.getId()) { } else if (v.getId() == binding.resizeTextView.getId()) {
onResizeClicked(); onResizeClicked();
} else if (v.getId() == captionTextView.getId()) { } else if (v.getId() == binding.captionTextView.getId()) {
onCaptionClicked(); onCaptionClicked();
} else if (v.getId() == playbackLiveSync.getId()) { } else if (v.getId() == binding.playbackLiveSync.getId()) {
seekToDefault(); seekToDefault();
} }
} }
@ -732,7 +694,7 @@ public abstract class VideoPlayer extends BasePlayer
final float speed = PLAYBACK_SPEEDS[speedIndex]; final float speed = PLAYBACK_SPEEDS[speedIndex];
setPlaybackSpeed(speed); setPlaybackSpeed(speed);
playbackSpeedTextView.setText(formatSpeed(speed)); playbackSpeed.setText(formatSpeed(speed));
} }
return false; return false;
@ -786,16 +748,17 @@ public abstract class VideoPlayer extends BasePlayer
} }
void onResizeClicked() { void onResizeClicked() {
if (getSurfaceView() != null) { if (binding != null) {
final int currentResizeMode = getSurfaceView().getResizeMode(); final int currentResizeMode = binding.surfaceView.getResizeMode();
final int newResizeMode = nextResizeMode(currentResizeMode); final int newResizeMode = nextResizeMode(currentResizeMode);
setResizeMode(newResizeMode); setResizeMode(newResizeMode);
} }
} }
protected void setResizeMode(@AspectRatioFrameLayout.ResizeMode final int resizeMode) { protected void setResizeMode(@AspectRatioFrameLayout.ResizeMode final int resizeMode) {
getSurfaceView().setResizeMode(resizeMode); binding.surfaceView.setResizeMode(resizeMode);
getResizeView().setText(PlayerHelper.resizeTypeOf(context, resizeMode)); ((TextView) binding.resizeTextView).setText(PlayerHelper.resizeTypeOf(context,
resizeMode));
} }
protected abstract int nextResizeMode(@AspectRatioFrameLayout.ResizeMode int resizeMode); protected abstract int nextResizeMode(@AspectRatioFrameLayout.ResizeMode int resizeMode);
@ -811,9 +774,8 @@ public abstract class VideoPlayer extends BasePlayer
Log.d(TAG, "onProgressChanged() called with: " Log.d(TAG, "onProgressChanged() called with: "
+ "seekBar = [" + seekBar + "], progress = [" + progress + "]"); + "seekBar = [" + seekBar + "], progress = [" + progress + "]");
} }
//if (fromUser) playbackCurrentTime.setText(getTimeString(progress));
if (fromUser) { if (fromUser) {
currentDisplaySeek.setText(getTimeString(progress)); binding.currentDisplaySeek.setText(getTimeString(progress));
} }
} }
@ -832,7 +794,7 @@ public abstract class VideoPlayer extends BasePlayer
} }
showControls(0); showControls(0);
animateView(currentDisplaySeek, AnimationUtils.Type.SCALE_AND_ALPHA, true, animateView(binding.currentDisplaySeek, AnimationUtils.Type.SCALE_AND_ALPHA, true,
DEFAULT_CONTROLS_DURATION); DEFAULT_CONTROLS_DURATION);
} }
@ -847,8 +809,9 @@ public abstract class VideoPlayer extends BasePlayer
simpleExoPlayer.setPlayWhenReady(true); simpleExoPlayer.setPlayWhenReady(true);
} }
playbackCurrentTime.setText(getTimeString(seekBar.getProgress())); binding.playbackCurrentTime.setText(getTimeString(seekBar.getProgress()));
animateView(currentDisplaySeek, AnimationUtils.Type.SCALE_AND_ALPHA, false, 200); animateView(binding.currentDisplaySeek, AnimationUtils.Type.SCALE_AND_ALPHA, false,
200);
if (getCurrentState() == STATE_PAUSED_SEEK) { if (getCurrentState() == STATE_PAUSED_SEEK) {
changeState(STATE_BUFFERING); changeState(STATE_BUFFERING);
@ -877,7 +840,8 @@ public abstract class VideoPlayer extends BasePlayer
} }
public boolean isControlsVisible() { public boolean isControlsVisible() {
return controlsRoot != null && controlsRoot.getVisibility() == View.VISIBLE; return binding != null
&& binding.playbackControlRoot.getVisibility() == View.VISIBLE;
} }
/** /**
@ -900,8 +864,9 @@ public abstract class VideoPlayer extends BasePlayer
} }
if (drawableId == -1) { if (drawableId == -1) {
if (controlAnimationView.getVisibility() == View.VISIBLE) { if (binding.controlAnimationView.getVisibility() == View.VISIBLE) {
controlViewAnimator = ObjectAnimator.ofPropertyValuesHolder(controlAnimationView, controlViewAnimator = ObjectAnimator.ofPropertyValuesHolder(
binding.controlAnimationView,
PropertyValuesHolder.ofFloat(View.ALPHA, 1.0f, 0.0f), PropertyValuesHolder.ofFloat(View.ALPHA, 1.0f, 0.0f),
PropertyValuesHolder.ofFloat(View.SCALE_X, 1.4f, 1.0f), PropertyValuesHolder.ofFloat(View.SCALE_X, 1.4f, 1.0f),
PropertyValuesHolder.ofFloat(View.SCALE_Y, 1.4f, 1.0f) PropertyValuesHolder.ofFloat(View.SCALE_Y, 1.4f, 1.0f)
@ -909,7 +874,7 @@ public abstract class VideoPlayer extends BasePlayer
controlViewAnimator.addListener(new AnimatorListenerAdapter() { controlViewAnimator.addListener(new AnimatorListenerAdapter() {
@Override @Override
public void onAnimationEnd(final Animator animation) { public void onAnimationEnd(final Animator animation) {
controlAnimationView.setVisibility(View.GONE); binding.controlAnimationView.setVisibility(View.GONE);
} }
}); });
controlViewAnimator.start(); controlViewAnimator.start();
@ -923,7 +888,8 @@ public abstract class VideoPlayer extends BasePlayer
final float alphaTo = goneOnEnd ? 0f : 1f; final float alphaTo = goneOnEnd ? 0f : 1f;
controlViewAnimator = ObjectAnimator.ofPropertyValuesHolder(controlAnimationView, controlViewAnimator = ObjectAnimator.ofPropertyValuesHolder(
binding.controlAnimationView,
PropertyValuesHolder.ofFloat(View.ALPHA, alphaFrom, alphaTo), PropertyValuesHolder.ofFloat(View.ALPHA, alphaFrom, alphaTo),
PropertyValuesHolder.ofFloat(View.SCALE_X, scaleFrom, scaleTo), PropertyValuesHolder.ofFloat(View.SCALE_X, scaleFrom, scaleTo),
PropertyValuesHolder.ofFloat(View.SCALE_Y, scaleFrom, scaleTo) PropertyValuesHolder.ofFloat(View.SCALE_Y, scaleFrom, scaleTo)
@ -932,17 +898,14 @@ public abstract class VideoPlayer extends BasePlayer
controlViewAnimator.addListener(new AnimatorListenerAdapter() { controlViewAnimator.addListener(new AnimatorListenerAdapter() {
@Override @Override
public void onAnimationEnd(final Animator animation) { public void onAnimationEnd(final Animator animation) {
if (goneOnEnd) { binding.controlAnimationView.setVisibility(goneOnEnd ? View.GONE
controlAnimationView.setVisibility(View.GONE); : View.VISIBLE);
} else {
controlAnimationView.setVisibility(View.VISIBLE);
}
} }
}); });
binding.controlAnimationView.setVisibility(View.VISIBLE);
controlAnimationView.setVisibility(View.VISIBLE); binding.controlAnimationView.setImageDrawable(AppCompatResources.getDrawable(context,
controlAnimationView.setImageDrawable(AppCompatResources.getDrawable(context, drawableId)); drawableId));
controlViewAnimator.start(); controlViewAnimator.start();
} }
@ -955,12 +918,12 @@ public abstract class VideoPlayer extends BasePlayer
Log.d(TAG, "showControlsThenHide() called"); Log.d(TAG, "showControlsThenHide() called");
} }
final int hideTime = controlsRoot.isInTouchMode() final int hideTime = binding.playbackControlRoot.isInTouchMode()
? DEFAULT_CONTROLS_HIDE_TIME ? DEFAULT_CONTROLS_HIDE_TIME
: DPAD_CONTROLS_HIDE_TIME; : DPAD_CONTROLS_HIDE_TIME;
showHideShadow(true, DEFAULT_CONTROLS_DURATION, 0); showHideShadow(true, DEFAULT_CONTROLS_DURATION, 0);
animateView(controlsRoot, true, DEFAULT_CONTROLS_DURATION, 0, animateView(binding.playbackControlRoot, true, DEFAULT_CONTROLS_DURATION, 0,
() -> hideControls(DEFAULT_CONTROLS_DURATION, hideTime)); () -> hideControls(DEFAULT_CONTROLS_DURATION, hideTime));
} }
@ -970,17 +933,18 @@ public abstract class VideoPlayer extends BasePlayer
} }
controlsVisibilityHandler.removeCallbacksAndMessages(null); controlsVisibilityHandler.removeCallbacksAndMessages(null);
showHideShadow(true, duration, 0); showHideShadow(true, duration, 0);
animateView(controlsRoot, true, duration); animateView(binding.playbackControlRoot, true, duration);
} }
public void safeHideControls(final long duration, final long delay) { public void safeHideControls(final long duration, final long delay) {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "safeHideControls() called with: delay = [" + delay + "]"); Log.d(TAG, "safeHideControls() called with: delay = [" + delay + "]");
} }
if (rootView.isInTouchMode()) { if (binding.getRoot().isInTouchMode()) {
controlsVisibilityHandler.removeCallbacksAndMessages(null); controlsVisibilityHandler.removeCallbacksAndMessages(null);
controlsVisibilityHandler.postDelayed( controlsVisibilityHandler.postDelayed(
() -> animateView(controlsRoot, false, duration), delay); () -> animateView(binding.playbackControlRoot, false, duration),
delay);
} }
} }
@ -991,7 +955,7 @@ public abstract class VideoPlayer extends BasePlayer
controlsVisibilityHandler.removeCallbacksAndMessages(null); controlsVisibilityHandler.removeCallbacksAndMessages(null);
controlsVisibilityHandler.postDelayed(() -> { controlsVisibilityHandler.postDelayed(() -> {
showHideShadow(false, duration, 0); showHideShadow(false, duration, 0);
animateView(controlsRoot, false, duration); animateView(binding.playbackControlRoot, false, duration);
}, delay); }, delay);
} }
@ -1007,13 +971,13 @@ public abstract class VideoPlayer extends BasePlayer
private Runnable hideControlsAndButtonHandler(final long duration, final View videoPlayPause) { private Runnable hideControlsAndButtonHandler(final long duration, final View videoPlayPause) {
return () -> { return () -> {
videoPlayPause.setVisibility(View.INVISIBLE); videoPlayPause.setVisibility(View.INVISIBLE);
animateView(controlsRoot, false, duration); animateView(binding.playbackControlRoot, false, duration);
}; };
} }
void showHideShadow(final boolean show, final long duration, final long delay) { void showHideShadow(final boolean show, final long duration, final long delay) {
animateView(playerTopShadow, show, duration, delay, null); animateView(binding.playerTopShadow, show, duration, delay, null);
animateView(playerBottomShadow, show, duration, delay, null); animateView(binding.playerBottomShadow, show, duration, delay, null);
} }
public abstract void hideSystemUIIfNeeded(); public abstract void hideSystemUIIfNeeded();
@ -1032,7 +996,7 @@ public abstract class VideoPlayer extends BasePlayer
} }
public ExpandableSurfaceView getSurfaceView() { public ExpandableSurfaceView getSurfaceView() {
return surfaceView; return binding.surfaceView;
} }
public boolean wasPlaying() { public boolean wasPlaying() {
@ -1050,83 +1014,23 @@ public abstract class VideoPlayer extends BasePlayer
return controlsVisibilityHandler; return controlsVisibilityHandler;
} }
@NonNull
public View getRootView() { public View getRootView() {
return rootView; return binding.getRoot();
}
public void setRootView(final View rootView) {
this.rootView = rootView;
} }
@NonNull
public View getLoadingPanel() { public View getLoadingPanel() {
return loadingPanel; return binding.loadingPanel;
} }
public ImageView getEndScreen() { @NonNull
return endScreen; public View getPlaybackControlRoot() {
} return binding.playbackControlRoot;
public ImageView getControlAnimationView() {
return controlAnimationView;
}
public View getControlsRoot() {
return controlsRoot;
}
public View getBottomControlsRoot() {
return bottomControlsRoot;
}
public SeekBar getPlaybackSeekBar() {
return playbackSeekBar;
}
public TextView getPlaybackCurrentTime() {
return playbackCurrentTime;
}
public TextView getPlaybackEndTime() {
return playbackEndTime;
}
public LinearLayout getTopControlsRoot() {
return topControlsRoot;
}
public TextView getQualityTextView() {
return qualityTextView;
}
public PopupMenu getQualityPopupMenu() {
return qualityPopupMenu;
}
public TextView getPlaybackSpeedTextView() {
return playbackSpeedTextView;
}
public PopupMenu getPlaybackSpeedPopupMenu() {
return playbackSpeedPopupMenu;
}
public View getSurfaceForeground() {
return surfaceForeground;
} }
@NonNull
public TextView getCurrentDisplaySeek() { public TextView getCurrentDisplaySeek() {
return currentDisplaySeek; return binding.currentDisplaySeek;
}
public SubtitleView getSubtitleView() {
return subtitleView;
}
public TextView getResizeView() {
return resizeView;
}
public TextView getCaptionTextView() {
return captionTextView;
} }
} }

View File

@ -371,7 +371,7 @@ abstract class BasePlayerGestureListener(
} }
if (!isMovingInPopup) { if (!isMovingInPopup) {
AnimationUtils.animateView(playerImpl.closeOverlayButton, true, 200) AnimationUtils.animateView(playerImpl.closeButton, true, 200)
} }
isMovingInPopup = true isMovingInPopup = true

View File

@ -123,7 +123,7 @@ public class PlayerGestureListener
} }
} else /* MainPlayer.PlayerType.POPUP */ { } else /* MainPlayer.PlayerType.POPUP */ {
final View closingOverlayView = playerImpl.getClosingOverlayView(); final View closingOverlayView = playerImpl.getClosingOverlay();
if (playerImpl.isInsideClosingRadius(movingEvent)) { if (playerImpl.isInsideClosingRadius(movingEvent)) {
if (closingOverlayView.getVisibility() == View.GONE) { if (closingOverlayView.getVisibility() == View.GONE) {
animateView(closingOverlayView, true, 250); animateView(closingOverlayView, true, 250);
@ -240,10 +240,10 @@ public class PlayerGestureListener
if (playerImpl.isInsideClosingRadius(event)) { if (playerImpl.isInsideClosingRadius(event)) {
playerImpl.closePopup(); playerImpl.closePopup();
} else { } else {
animateView(playerImpl.getClosingOverlayView(), false, 0); animateView(playerImpl.getClosingOverlay(), false, 0);
if (!playerImpl.isPopupClosing) { if (!playerImpl.isPopupClosing) {
animateView(playerImpl.getCloseOverlayButton(), false, 200); animateView(playerImpl.getCloseButton(), false, 200);
} }
} }
} }