Switched video player to ViewBinding
This commit is contained in:
parent
33ad1a91f0
commit
ac0580400e
|
@ -31,6 +31,6 @@ public class VideoplayerActivityTest {
|
||||||
@Test
|
@Test
|
||||||
public void testStartActivity() throws Exception {
|
public void testStartActivity() throws Exception {
|
||||||
activityTestRule.launchActivity(new Intent());
|
activityTestRule.launchActivity(new Intent());
|
||||||
onView(withId(R.id.videoframe)).check(matches(isDisplayed()));
|
onView(withId(R.id.videoPlayerContainer)).check(matches(isDisplayed()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,42 +9,31 @@ import android.media.AudioManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.view.Gravity;
|
|
||||||
import android.view.KeyEvent;
|
|
||||||
import android.view.MenuInflater;
|
|
||||||
import android.view.animation.AlphaAnimation;
|
|
||||||
import android.view.animation.AnimationSet;
|
|
||||||
import android.view.animation.ScaleAnimation;
|
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.ImageButton;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
|
|
||||||
import android.widget.TextView;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
|
||||||
import androidx.cardview.widget.CardView;
|
|
||||||
import androidx.core.app.ActivityOptionsCompat;
|
|
||||||
import androidx.core.view.WindowCompat;
|
|
||||||
import androidx.appcompat.app.ActionBar;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
import android.view.Gravity;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.SurfaceHolder;
|
import android.view.SurfaceHolder;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
import android.view.animation.AlphaAnimation;
|
||||||
import android.view.animation.Animation;
|
import android.view.animation.Animation;
|
||||||
|
import android.view.animation.AnimationSet;
|
||||||
import android.view.animation.AnimationUtils;
|
import android.view.animation.AnimationUtils;
|
||||||
|
import android.view.animation.ScaleAnimation;
|
||||||
|
import android.widget.EditText;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.ProgressBar;
|
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import java.lang.ref.WeakReference;
|
import androidx.appcompat.app.ActionBar;
|
||||||
import java.text.NumberFormat;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import androidx.core.app.ActivityOptionsCompat;
|
||||||
|
import androidx.core.view.WindowCompat;
|
||||||
import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
|
import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
|
@ -64,6 +53,7 @@ import de.danoeh.antennapod.core.util.TimeSpeedConverter;
|
||||||
import de.danoeh.antennapod.core.util.gui.PictureInPictureUtil;
|
import de.danoeh.antennapod.core.util.gui.PictureInPictureUtil;
|
||||||
import de.danoeh.antennapod.core.util.playback.MediaPlayerError;
|
import de.danoeh.antennapod.core.util.playback.MediaPlayerError;
|
||||||
import de.danoeh.antennapod.core.util.playback.PlaybackController;
|
import de.danoeh.antennapod.core.util.playback.PlaybackController;
|
||||||
|
import de.danoeh.antennapod.databinding.VideoplayerActivityBinding;
|
||||||
import de.danoeh.antennapod.dialog.PlaybackControlsDialog;
|
import de.danoeh.antennapod.dialog.PlaybackControlsDialog;
|
||||||
import de.danoeh.antennapod.dialog.ShareDialog;
|
import de.danoeh.antennapod.dialog.ShareDialog;
|
||||||
import de.danoeh.antennapod.dialog.SkipPreferenceDialog;
|
import de.danoeh.antennapod.dialog.SkipPreferenceDialog;
|
||||||
|
@ -72,8 +62,6 @@ import de.danoeh.antennapod.model.feed.FeedItem;
|
||||||
import de.danoeh.antennapod.model.feed.FeedMedia;
|
import de.danoeh.antennapod.model.feed.FeedMedia;
|
||||||
import de.danoeh.antennapod.model.playback.Playable;
|
import de.danoeh.antennapod.model.playback.Playable;
|
||||||
import de.danoeh.antennapod.ui.appstartintent.MainActivityStarter;
|
import de.danoeh.antennapod.ui.appstartintent.MainActivityStarter;
|
||||||
import de.danoeh.antennapod.view.AspectRatioVideoView;
|
|
||||||
import de.danoeh.antennapod.view.PlayButton;
|
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.disposables.Disposable;
|
import io.reactivex.disposables.Disposable;
|
||||||
|
@ -83,6 +71,8 @@ import org.greenrobot.eventbus.EventBus;
|
||||||
import org.greenrobot.eventbus.Subscribe;
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
import org.greenrobot.eventbus.ThreadMode;
|
import org.greenrobot.eventbus.ThreadMode;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Activity for playing video files.
|
* Activity for playing video files.
|
||||||
*/
|
*/
|
||||||
|
@ -96,29 +86,8 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar.
|
||||||
private boolean videoSurfaceCreated = false;
|
private boolean videoSurfaceCreated = false;
|
||||||
private boolean destroyingDueToReload = false;
|
private boolean destroyingDueToReload = false;
|
||||||
private long lastScreenTap = 0;
|
private long lastScreenTap = 0;
|
||||||
|
|
||||||
private VideoControlsHider videoControlsHider = new VideoControlsHider(this);
|
private VideoControlsHider videoControlsHider = new VideoControlsHider(this);
|
||||||
|
private VideoplayerActivityBinding viewBinding;
|
||||||
private final AtomicBoolean isSetup = new AtomicBoolean(false);
|
|
||||||
|
|
||||||
private LinearLayout controls;
|
|
||||||
private LinearLayout videoOverlay;
|
|
||||||
private AspectRatioVideoView videoview;
|
|
||||||
private ProgressBar progressIndicator;
|
|
||||||
private FrameLayout videoframe;
|
|
||||||
private ImageView skipAnimationView;
|
|
||||||
private TextView txtvPosition;
|
|
||||||
private TextView txtvLength;
|
|
||||||
private SeekBar sbPosition;
|
|
||||||
private ImageButton butRev;
|
|
||||||
private TextView txtvRev;
|
|
||||||
private PlayButton butPlay;
|
|
||||||
private ImageButton butFF;
|
|
||||||
private TextView txtvFF;
|
|
||||||
private ImageButton butSkip;
|
|
||||||
private CardView cardViewSeek;
|
|
||||||
private TextView txtvSeek;
|
|
||||||
|
|
||||||
private PlaybackController controller;
|
private PlaybackController controller;
|
||||||
private boolean showTimeLeft = false;
|
private boolean showTimeLeft = false;
|
||||||
private boolean isFavorite = false;
|
private boolean isFavorite = false;
|
||||||
|
@ -138,8 +107,11 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar.
|
||||||
StorageUtils.checkStorageAvailability(this);
|
StorageUtils.checkStorageAvailability(this);
|
||||||
|
|
||||||
getWindow().setFormat(PixelFormat.TRANSPARENT);
|
getWindow().setFormat(PixelFormat.TRANSPARENT);
|
||||||
|
viewBinding = VideoplayerActivityBinding.inflate(LayoutInflater.from(this));
|
||||||
|
setContentView(viewBinding.getRoot());
|
||||||
setupGUI();
|
setupGUI();
|
||||||
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(0x80000000));
|
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(0x80000000));
|
||||||
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -170,7 +142,8 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar.
|
||||||
if (!PictureInPictureUtil.isInPictureInPictureMode(this)) {
|
if (!PictureInPictureUtil.isInPictureInPictureMode(this)) {
|
||||||
videoControlsHider.stop();
|
videoControlsHider.stop();
|
||||||
}
|
}
|
||||||
progressIndicator.setVisibility(View.GONE); // Controller released; we will not receive buffering updates
|
// Controller released; we will not receive buffering updates
|
||||||
|
viewBinding.progressBar.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -230,19 +203,17 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar.
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBufferStart() {
|
public void onBufferStart() {
|
||||||
progressIndicator.setVisibility(View.VISIBLE);
|
viewBinding.progressBar.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBufferEnd() {
|
public void onBufferEnd() {
|
||||||
progressIndicator.setVisibility(View.INVISIBLE);
|
viewBinding.progressBar.setVisibility(View.INVISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBufferUpdate(float progress) {
|
public void onBufferUpdate(float progress) {
|
||||||
if (sbPosition != null) {
|
viewBinding.sbPosition.setSecondaryProgress((int) (progress * viewBinding.sbPosition.getMax()));
|
||||||
sbPosition.setSecondaryProgress((int) (progress * sbPosition.getMax()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -266,7 +237,7 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar.
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updatePlayButtonShowsPlay(boolean showPlay) {
|
protected void updatePlayButtonShowsPlay(boolean showPlay) {
|
||||||
butPlay.setIsShowPlay(showPlay);
|
viewBinding.playButton.setIsShowPlay(showPlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -279,7 +250,7 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar.
|
||||||
setupVideoAspectRatio();
|
setupVideoAspectRatio();
|
||||||
if (videoSurfaceCreated && controller != null) {
|
if (videoSurfaceCreated && controller != null) {
|
||||||
Log.d(TAG, "Videosurface already created, setting videosurface now");
|
Log.d(TAG, "Videosurface already created, setting videosurface now");
|
||||||
controller.setVideoSurface(videoview.getHolder());
|
controller.setVideoSurface(viewBinding.videoView.getHolder());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,20 +286,9 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar.
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setupGUI() {
|
protected void setupGUI() {
|
||||||
if (isSetup.getAndSet(true)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setContentView(R.layout.videoplayer_activity);
|
|
||||||
sbPosition = findViewById(R.id.sbPosition);
|
|
||||||
txtvPosition = findViewById(R.id.txtvPosition);
|
|
||||||
cardViewSeek = findViewById(R.id.cardViewSeek);
|
|
||||||
txtvSeek = findViewById(R.id.txtvSeek);
|
|
||||||
|
|
||||||
showTimeLeft = UserPreferences.shouldShowRemainingTime();
|
showTimeLeft = UserPreferences.shouldShowRemainingTime();
|
||||||
Log.d("timeleft", showTimeLeft ? "true" : "false");
|
Log.d("timeleft", showTimeLeft ? "true" : "false");
|
||||||
txtvLength = findViewById(R.id.txtvLength);
|
viewBinding.durationLabel.setOnClickListener(v -> {
|
||||||
if (txtvLength != null) {
|
|
||||||
txtvLength.setOnClickListener(v -> {
|
|
||||||
showTimeLeft = !showTimeLeft;
|
showTimeLeft = !showTimeLeft;
|
||||||
Playable media = controller.getMedia();
|
Playable media = controller.getMedia();
|
||||||
if (media == null) {
|
if (media == null) {
|
||||||
|
@ -346,77 +306,41 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar.
|
||||||
int duration = converter.convert(media.getDuration());
|
int duration = converter.convert(media.getDuration());
|
||||||
length = Converter.getDurationStringLong(duration);
|
length = Converter.getDurationStringLong(duration);
|
||||||
}
|
}
|
||||||
txtvLength.setText(length);
|
viewBinding.durationLabel.setText(length);
|
||||||
|
|
||||||
UserPreferences.setShowRemainTimeSetting(showTimeLeft);
|
UserPreferences.setShowRemainTimeSetting(showTimeLeft);
|
||||||
Log.d("timeleft on click", showTimeLeft ? "true" : "false");
|
Log.d("timeleft on click", showTimeLeft ? "true" : "false");
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
butRev = findViewById(R.id.butRev);
|
viewBinding.sbPosition.setOnSeekBarChangeListener(this);
|
||||||
txtvRev = findViewById(R.id.txtvRev);
|
viewBinding.rewindButton.setOnClickListener(v -> onRewind());
|
||||||
if (txtvRev != null) {
|
viewBinding.rewindButton.setOnLongClickListener(v -> {
|
||||||
txtvRev.setText(NumberFormat.getInstance().format(UserPreferences.getRewindSecs()));
|
|
||||||
}
|
|
||||||
butPlay = findViewById(R.id.butPlay);
|
|
||||||
butPlay.setIsVideoScreen(true);
|
|
||||||
butFF = findViewById(R.id.butFF);
|
|
||||||
txtvFF = findViewById(R.id.txtvFF);
|
|
||||||
if (txtvFF != null) {
|
|
||||||
txtvFF.setText(NumberFormat.getInstance().format(UserPreferences.getFastForwardSecs()));
|
|
||||||
}
|
|
||||||
butSkip = findViewById(R.id.butSkip);
|
|
||||||
|
|
||||||
// SEEKBAR SETUP
|
|
||||||
|
|
||||||
sbPosition.setOnSeekBarChangeListener(this);
|
|
||||||
|
|
||||||
// BUTTON SETUP
|
|
||||||
|
|
||||||
if (butRev != null) {
|
|
||||||
butRev.setOnClickListener(v -> onRewind());
|
|
||||||
butRev.setOnLongClickListener(v -> {
|
|
||||||
SkipPreferenceDialog.showSkipPreference(VideoplayerActivity.this,
|
SkipPreferenceDialog.showSkipPreference(VideoplayerActivity.this,
|
||||||
SkipPreferenceDialog.SkipDirection.SKIP_REWIND, txtvRev);
|
SkipPreferenceDialog.SkipDirection.SKIP_REWIND, null);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
viewBinding.playButton.setIsVideoScreen(true);
|
||||||
|
viewBinding.playButton.setOnClickListener(v -> onPlayPause());
|
||||||
butPlay.setOnClickListener(v -> onPlayPause());
|
viewBinding.fastForwardButton.setOnClickListener(v -> onFastForward());
|
||||||
|
viewBinding.fastForwardButton.setOnLongClickListener(v -> {
|
||||||
if (butFF != null) {
|
|
||||||
butFF.setOnClickListener(v -> onFastForward());
|
|
||||||
butFF.setOnLongClickListener(v -> {
|
|
||||||
SkipPreferenceDialog.showSkipPreference(VideoplayerActivity.this,
|
SkipPreferenceDialog.showSkipPreference(VideoplayerActivity.this,
|
||||||
SkipPreferenceDialog.SkipDirection.SKIP_FORWARD, txtvFF);
|
SkipPreferenceDialog.SkipDirection.SKIP_FORWARD, null);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
// To suppress touches directly below the slider
|
||||||
|
viewBinding.bottomControlsContainer.setOnTouchListener((view, motionEvent) -> true);
|
||||||
if (butSkip != null) {
|
viewBinding.bottomControlsContainer.setFitsSystemWindows(true);
|
||||||
butSkip.setOnClickListener(v ->
|
viewBinding.videoView.getHolder().addCallback(surfaceHolderCallback);
|
||||||
IntentUtils.sendLocalBroadcast(VideoplayerActivity.this, PlaybackService.ACTION_SKIP_CURRENT_EPISODE));
|
viewBinding.videoView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
|
||||||
}
|
|
||||||
|
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
||||||
controls = findViewById(R.id.controls);
|
|
||||||
videoOverlay = findViewById(R.id.overlay);
|
|
||||||
videoview = findViewById(R.id.videoview);
|
|
||||||
videoframe = findViewById(R.id.videoframe);
|
|
||||||
progressIndicator = findViewById(R.id.progressIndicator);
|
|
||||||
skipAnimationView = findViewById(R.id.skip_animation);
|
|
||||||
videoview.getHolder().addCallback(surfaceHolderCallback);
|
|
||||||
videoframe.setOnTouchListener(onVideoviewTouched);
|
|
||||||
videoOverlay.setOnTouchListener((view, motionEvent) -> true); // To suppress touches directly below the slider
|
|
||||||
videoview.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
|
|
||||||
videoOverlay.setFitsSystemWindows(true);
|
|
||||||
|
|
||||||
setupVideoControlsToggler();
|
setupVideoControlsToggler();
|
||||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||||
|
|
||||||
videoframe.getViewTreeObserver().addOnGlobalLayoutListener(() ->
|
viewBinding.videoPlayerContainer.setOnTouchListener(onVideoviewTouched);
|
||||||
videoview.setAvailableSize(videoframe.getWidth(), videoframe.getHeight()));
|
viewBinding.videoPlayerContainer.getViewTreeObserver().addOnGlobalLayoutListener(() ->
|
||||||
|
viewBinding.videoView.setAvailableSize(
|
||||||
|
viewBinding.videoPlayerContainer.getWidth(), viewBinding.videoPlayerContainer.getHeight()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private final View.OnTouchListener onVideoviewTouched = (v, event) -> {
|
private final View.OnTouchListener onVideoviewTouched = (v, event) -> {
|
||||||
|
@ -462,18 +386,18 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar.
|
||||||
skipAnimation.setFillAfter(false);
|
skipAnimation.setFillAfter(false);
|
||||||
skipAnimation.setDuration(800);
|
skipAnimation.setDuration(800);
|
||||||
|
|
||||||
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) skipAnimationView.getLayoutParams();
|
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) viewBinding.skipAnimationImage.getLayoutParams();
|
||||||
if (isForward) {
|
if (isForward) {
|
||||||
skipAnimationView.setImageResource(R.drawable.ic_fast_forward_video_white);
|
viewBinding.skipAnimationImage.setImageResource(R.drawable.ic_fast_forward_video_white);
|
||||||
params.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;
|
params.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;
|
||||||
} else {
|
} else {
|
||||||
skipAnimationView.setImageResource(R.drawable.ic_fast_rewind_video_white);
|
viewBinding.skipAnimationImage.setImageResource(R.drawable.ic_fast_rewind_video_white);
|
||||||
params.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;
|
params.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
skipAnimationView.setVisibility(View.VISIBLE);
|
viewBinding.skipAnimationImage.setVisibility(View.VISIBLE);
|
||||||
skipAnimationView.setLayoutParams(params);
|
viewBinding.skipAnimationImage.setLayoutParams(params);
|
||||||
skipAnimationView.startAnimation(skipAnimation);
|
viewBinding.skipAnimationImage.startAnimation(skipAnimation);
|
||||||
skipAnimation.setAnimationListener(new Animation.AnimationListener() {
|
skipAnimation.setAnimationListener(new Animation.AnimationListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onAnimationStart(Animation animation) {
|
public void onAnimationStart(Animation animation) {
|
||||||
|
@ -481,7 +405,7 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar.
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAnimationEnd(Animation animation) {
|
public void onAnimationEnd(Animation animation) {
|
||||||
skipAnimationView.setVisibility(View.GONE);
|
viewBinding.skipAnimationImage.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -502,7 +426,7 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar.
|
||||||
Pair<Integer, Integer> videoSize = controller.getVideoSize();
|
Pair<Integer, Integer> videoSize = controller.getVideoSize();
|
||||||
if (videoSize != null && videoSize.first > 0 && videoSize.second > 0) {
|
if (videoSize != null && videoSize.first > 0 && videoSize.second > 0) {
|
||||||
Log.d(TAG, "Width,height of video: " + videoSize.first + ", " + videoSize.second);
|
Log.d(TAG, "Width,height of video: " + videoSize.first + ", " + videoSize.second);
|
||||||
videoview.setVideoSize(videoSize.first, videoSize.second);
|
viewBinding.videoView.setVideoSize(videoSize.first, videoSize.second);
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "Could not determine video size");
|
Log.e(TAG, "Could not determine video size");
|
||||||
}
|
}
|
||||||
|
@ -530,7 +454,7 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar.
|
||||||
}
|
}
|
||||||
|
|
||||||
void onPlayPause() {
|
void onPlayPause() {
|
||||||
if(controller == null) {
|
if (controller == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
controller.init();
|
controller.init();
|
||||||
|
@ -594,14 +518,14 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar.
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
private void showVideoControls() {
|
private void showVideoControls() {
|
||||||
videoOverlay.setVisibility(View.VISIBLE);
|
viewBinding.bottomControlsContainer.setVisibility(View.VISIBLE);
|
||||||
controls.setVisibility(View.VISIBLE);
|
viewBinding.controlsContainer.setVisibility(View.VISIBLE);
|
||||||
final Animation animation = AnimationUtils.loadAnimation(this, R.anim.fade_in);
|
final Animation animation = AnimationUtils.loadAnimation(this, R.anim.fade_in);
|
||||||
if (animation != null) {
|
if (animation != null) {
|
||||||
videoOverlay.startAnimation(animation);
|
viewBinding.bottomControlsContainer.startAnimation(animation);
|
||||||
controls.startAnimation(animation);
|
viewBinding.controlsContainer.startAnimation(animation);
|
||||||
}
|
}
|
||||||
videoview.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
|
viewBinding.videoView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
|
@ -609,17 +533,17 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar.
|
||||||
if (showAnimation) {
|
if (showAnimation) {
|
||||||
final Animation animation = AnimationUtils.loadAnimation(this, R.anim.fade_out);
|
final Animation animation = AnimationUtils.loadAnimation(this, R.anim.fade_out);
|
||||||
if (animation != null) {
|
if (animation != null) {
|
||||||
videoOverlay.startAnimation(animation);
|
viewBinding.bottomControlsContainer.startAnimation(animation);
|
||||||
controls.startAnimation(animation);
|
viewBinding.controlsContainer.startAnimation(animation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
|
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
|
||||||
| View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
| View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
||||||
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
|
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
|
||||||
videoOverlay.setFitsSystemWindows(true);
|
viewBinding.bottomControlsContainer.setFitsSystemWindows(true);
|
||||||
|
|
||||||
videoOverlay.setVisibility(View.GONE);
|
viewBinding.bottomControlsContainer.setVisibility(View.GONE);
|
||||||
controls.setVisibility(View.GONE);
|
viewBinding.controlsContainer.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hideVideoControls() {
|
private void hideVideoControls() {
|
||||||
|
@ -774,7 +698,7 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar.
|
||||||
}
|
}
|
||||||
|
|
||||||
void onPositionObserverUpdate() {
|
void onPositionObserverUpdate() {
|
||||||
if (controller == null || txtvPosition == null || txtvLength == null) {
|
if (controller == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -789,42 +713,39 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar.
|
||||||
Log.w(TAG, "Could not react to position observer update because of invalid time");
|
Log.w(TAG, "Could not react to position observer update because of invalid time");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
txtvPosition.setText(Converter.getDurationStringLong(currentPosition));
|
viewBinding.positionLabel.setText(Converter.getDurationStringLong(currentPosition));
|
||||||
if (showTimeLeft) {
|
if (showTimeLeft) {
|
||||||
txtvLength.setText("-" + Converter.getDurationStringLong(remainingTime));
|
viewBinding.durationLabel.setText("-" + Converter.getDurationStringLong(remainingTime));
|
||||||
} else {
|
} else {
|
||||||
txtvLength.setText(Converter.getDurationStringLong(duration));
|
viewBinding.durationLabel.setText(Converter.getDurationStringLong(duration));
|
||||||
}
|
}
|
||||||
updateProgressbarPosition(currentPosition, duration);
|
updateProgressbarPosition(currentPosition, duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateProgressbarPosition(int position, int duration) {
|
private void updateProgressbarPosition(int position, int duration) {
|
||||||
Log.d(TAG, "updateProgressbarPosition(" + position + ", " + duration + ")");
|
Log.d(TAG, "updateProgressbarPosition(" + position + ", " + duration + ")");
|
||||||
if(sbPosition == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
float progress = ((float) position) / duration;
|
float progress = ((float) position) / duration;
|
||||||
sbPosition.setProgress((int) (progress * sbPosition.getMax()));
|
viewBinding.sbPosition.setProgress((int) (progress * viewBinding.sbPosition.getMax()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||||
if (controller == null || txtvLength == null) {
|
if (controller == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (fromUser) {
|
if (fromUser) {
|
||||||
prog = progress / ((float) seekBar.getMax());
|
prog = progress / ((float) seekBar.getMax());
|
||||||
TimeSpeedConverter converter = new TimeSpeedConverter(controller.getCurrentPlaybackSpeedMultiplier());
|
TimeSpeedConverter converter = new TimeSpeedConverter(controller.getCurrentPlaybackSpeedMultiplier());
|
||||||
int position = converter.convert((int) (prog * controller.getDuration()));
|
int position = converter.convert((int) (prog * controller.getDuration()));
|
||||||
txtvSeek.setText(Converter.getDurationStringLong(position));
|
viewBinding.seekPositionLabel.setText(Converter.getDurationStringLong(position));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||||
cardViewSeek.setScaleX(.8f);
|
viewBinding.seekCardView.setScaleX(.8f);
|
||||||
cardViewSeek.setScaleY(.8f);
|
viewBinding.seekCardView.setScaleY(.8f);
|
||||||
cardViewSeek.animate()
|
viewBinding.seekCardView.animate()
|
||||||
.setInterpolator(new FastOutSlowInInterpolator())
|
.setInterpolator(new FastOutSlowInInterpolator())
|
||||||
.alpha(1f).scaleX(1f).scaleY(1f)
|
.alpha(1f).scaleX(1f).scaleY(1f)
|
||||||
.setDuration(200)
|
.setDuration(200)
|
||||||
|
@ -837,9 +758,9 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar.
|
||||||
if (controller != null) {
|
if (controller != null) {
|
||||||
controller.seekTo((int) (prog * controller.getDuration()));
|
controller.seekTo((int) (prog * controller.getDuration()));
|
||||||
}
|
}
|
||||||
cardViewSeek.setScaleX(1f);
|
viewBinding.seekCardView.setScaleX(1f);
|
||||||
cardViewSeek.setScaleY(1f);
|
viewBinding.seekCardView.setScaleY(1f);
|
||||||
cardViewSeek.animate()
|
viewBinding.seekCardView.animate()
|
||||||
.setInterpolator(new FastOutSlowInInterpolator())
|
.setInterpolator(new FastOutSlowInInterpolator())
|
||||||
.alpha(0f).scaleX(.8f).scaleY(.8f)
|
.alpha(0f).scaleX(.8f).scaleY(.8f)
|
||||||
.setDuration(200)
|
.setDuration(200)
|
||||||
|
|
|
@ -6,16 +6,16 @@
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:background="@color/black"
|
android:background="@color/black"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:id="@+id/videoframe">
|
android:id="@+id/videoPlayerContainer">
|
||||||
|
|
||||||
<de.danoeh.antennapod.view.AspectRatioVideoView
|
<de.danoeh.antennapod.view.AspectRatioVideoView
|
||||||
android:id="@+id/videoview"
|
android:id="@+id/videoView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center" />
|
android:layout_gravity="center" />
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@+id/progressIndicator"
|
android:id="@+id/progressBar"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
android:visibility="invisible" />
|
android:visibility="invisible" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/controls"
|
android:id="@+id/controlsContainer"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
|
@ -33,7 +33,7 @@
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/butRev"
|
android:id="@+id/rewindButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="8dp"
|
android:layout_margin="8dp"
|
||||||
|
@ -42,7 +42,7 @@
|
||||||
app:srcCompat="@drawable/ic_fast_rewind_video_white" />
|
app:srcCompat="@drawable/ic_fast_rewind_video_white" />
|
||||||
|
|
||||||
<de.danoeh.antennapod.view.PlayButton
|
<de.danoeh.antennapod.view.PlayButton
|
||||||
android:id="@+id/butPlay"
|
android:id="@+id/playButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="8dp"
|
android:layout_margin="8dp"
|
||||||
|
@ -51,7 +51,7 @@
|
||||||
app:srcCompat="@drawable/ic_pause_video_white" />
|
app:srcCompat="@drawable/ic_pause_video_white" />
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/butFF"
|
android:id="@+id/fastForwardButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="8dp"
|
android:layout_margin="8dp"
|
||||||
|
@ -62,7 +62,7 @@
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/skip_animation"
|
android:id="@+id/skipAnimationImage"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
|
@ -70,14 +70,14 @@
|
||||||
android:layout_gravity="center"/>
|
android:layout_gravity="center"/>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/overlay"
|
android:id="@+id/bottomControlsContainer"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="bottom|center"
|
android:layout_gravity="bottom|center"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<androidx.cardview.widget.CardView
|
<androidx.cardview.widget.CardView
|
||||||
android:id="@+id/cardViewSeek"
|
android:id="@+id/seekCardView"
|
||||||
android:alpha="0"
|
android:alpha="0"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -89,7 +89,7 @@
|
||||||
tools:alpha="1">
|
tools:alpha="1">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/txtvSeek"
|
android:id="@+id/seekPositionLabel"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -104,7 +104,6 @@
|
||||||
</androidx.cardview.widget.CardView>
|
</androidx.cardview.widget.CardView>
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/timecontrol"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="50dp"
|
android:layout_height="50dp"
|
||||||
android:background="#80000000"
|
android:background="#80000000"
|
||||||
|
@ -112,7 +111,7 @@
|
||||||
android:paddingTop="8dp">
|
android:paddingTop="8dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/txtvPosition"
|
android:id="@+id/positionLabel"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
|
@ -129,7 +128,7 @@
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/txtvLength"
|
android:id="@+id/durationLabel"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
|
@ -149,10 +148,10 @@
|
||||||
android:id="@+id/sbPosition"
|
android:id="@+id/sbPosition"
|
||||||
android:layout_width="0px"
|
android:layout_width="0px"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_toLeftOf="@+id/txtvLength"
|
android:layout_toLeftOf="@+id/durationLabel"
|
||||||
android:layout_toStartOf="@+id/txtvLength"
|
android:layout_toStartOf="@+id/durationLabel"
|
||||||
android:layout_toRightOf="@+id/txtvPosition"
|
android:layout_toRightOf="@+id/positionLabel"
|
||||||
android:layout_toEndOf="@+id/txtvPosition"
|
android:layout_toEndOf="@+id/positionLabel"
|
||||||
android:layout_centerInParent="true"
|
android:layout_centerInParent="true"
|
||||||
android:max="500" />
|
android:max="500" />
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue