diff options
author | scria1000 <91804886+scria1000@users.noreply.github.com> | 2023-01-25 17:11:13 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-25 17:11:13 +0000 |
commit | c382512292c8376372a12abce86d2f5eb8b41049 (patch) | |
tree | c59fc1f63d920d357dc455c82721ed11a0a9ff8f /app/src/main | |
parent | ed738437e651057b4cde959593cc0505eef401f4 (diff) | |
download | infinity-for-reddit-c382512292c8376372a12abce86d2f5eb8b41049.tar infinity-for-reddit-c382512292c8376372a12abce86d2f5eb8b41049.tar.gz infinity-for-reddit-c382512292c8376372a12abce86d2f5eb8b41049.tar.bz2 infinity-for-reddit-c382512292c8376372a12abce86d2f5eb8b41049.tar.lz infinity-for-reddit-c382512292c8376372a12abce86d2f5eb8b41049.tar.xz infinity-for-reddit-c382512292c8376372a12abce86d2f5eb8b41049.tar.zst infinity-for-reddit-c382512292c8376372a12abce86d2f5eb8b41049.zip |
Remember paused state for autoplay videos (#1331)
* Remember paused state for autoplay videos
* Update cached playback info
Update cached playback info instead of keeping track of it with a local variable
* Add missing null check
* Move logic into play()
Diffstat (limited to '')
3 files changed, 322 insertions, 29 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java index 69fef736..22a070c9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java @@ -47,7 +47,9 @@ import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.target.Target; import com.google.android.exoplayer2.Tracks; import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; +import com.google.android.exoplayer2.ui.DefaultTimeBar; import com.google.android.exoplayer2.ui.PlayerView; +import com.google.android.exoplayer2.ui.TimeBar; import com.google.common.collect.ImmutableList; import com.libRG.CustomTextView; @@ -708,10 +710,12 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy } else { ((PostVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1); } - if (mFragment.getMasterMutingOption() == null) { - ((PostVideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (post.isNSFW() && mMuteNSFWVideo) ? 0f : 1f); - } else { - ((PostVideoAutoplayViewHolder) holder).setVolume(mFragment.getMasterMutingOption() ? 0f : 1f); + if (!((PostVideoAutoplayViewHolder) holder).isManuallyPaused) { + if (mFragment.getMasterMutingOption() == null) { + ((PostVideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (post.isNSFW() && mMuteNSFWVideo) ? 0f : 1f); + } else { + ((PostVideoAutoplayViewHolder) holder).setVolume(mFragment.getMasterMutingOption() ? 0f : 1f); + } } if ((post.isGfycat() || post.isRedgifs()) && !post.isLoadGfycatOrStreamableVideoSuccess()) { @@ -883,10 +887,12 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy } else { ((PostCard2VideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1); } - if (mFragment.getMasterMutingOption() == null) { - ((PostCard2VideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (post.isNSFW() && mMuteNSFWVideo) ? 0f : 1f); - } else { - ((PostCard2VideoAutoplayViewHolder) holder).setVolume(mFragment.getMasterMutingOption() ? 0f : 1f); + if (!((PostCard2VideoAutoplayViewHolder) holder).isManuallyPaused) { + if (mFragment.getMasterMutingOption() == null) { + ((PostCard2VideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (post.isNSFW() && mMuteNSFWVideo) ? 0f : 1f); + } else { + ((PostCard2VideoAutoplayViewHolder) holder).setVolume(mFragment.getMasterMutingOption() ? 0f : 1f); + } } if ((post.isGfycat() || post.isRedgifs()) && !post.isLoadGfycatOrStreamableVideoSuccess()) { @@ -1820,7 +1826,9 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy } ((PostVideoAutoplayViewHolder) holder).errorLoadingGfycatImageView.setVisibility(View.GONE); ((PostVideoAutoplayViewHolder) holder).muteButton.setVisibility(View.GONE); - ((PostVideoAutoplayViewHolder) holder).resetVolume(); + if (!((PostVideoAutoplayViewHolder) holder).isManuallyPaused) { + ((PostVideoAutoplayViewHolder) holder).resetVolume(); + } mGlide.clear(((PostVideoAutoplayViewHolder) holder).previewImageView); ((PostVideoAutoplayViewHolder) holder).previewImageView.setVisibility(View.GONE); } else if (holder instanceof PostWithPreviewTypeViewHolder) { @@ -2643,6 +2651,12 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy ImageView muteButton; @BindView(R.id.fullscreen_exo_playback_control_view) ImageView fullscreenButton; + @BindView(R.id.exo_pause) + ImageView pauseButton; + @BindView(R.id.exo_play) + ImageView playButton; + @BindView(R.id.exo_progress) + DefaultTimeBar progressBar; @BindView(R.id.bottom_constraint_layout_item_post_video_type_autoplay) ConstraintLayout bottomConstraintLayout; @BindView(R.id.plus_button_item_post_video_type_autoplay) @@ -2659,10 +2673,13 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy ImageView shareButton; @Nullable + Container container; + @Nullable ExoPlayerViewHelper helper; private Uri mediaUri; private float volume; public Call<String> fetchGfycatOrStreamableVideoCall; + private boolean isManuallyPaused; PostVideoAutoplayViewHolder(View itemView) { super(itemView); @@ -2754,6 +2771,36 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy } }); + pauseButton.setOnClickListener(view -> { + pause(); + isManuallyPaused = true; + savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo()); + }); + + playButton.setOnClickListener(view -> { + isManuallyPaused = false; + play(); + }); + + progressBar.addListener(new TimeBar.OnScrubListener() { + @Override + public void onScrubStart(TimeBar timeBar, long position) { + + } + + @Override + public void onScrubMove(TimeBar timeBar, long position) { + + } + + @Override + public void onScrubStop(TimeBar timeBar, long position, boolean canceled) { + if (!canceled) { + savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo()); + } + } + }); + previewImageView.setOnClickListener(view -> fullscreenButton.performClick()); videoPlayer.setOnClickListener(view -> { @@ -2775,6 +2822,10 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy volume = 0f; } + private void savePlaybackInfo(int order, @Nullable PlaybackInfo playbackInfo) { + if (container != null) container.savePlaybackInfo(order, playbackInfo); + } + @NonNull @Override public View getPlayerView() { @@ -2792,6 +2843,9 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy if (mediaUri == null) { return; } + if (this.container == null) { + this.container = container; + } if (helper == null) { helper = new ExoPlayerViewHelper(this, mediaUri, null, mExoCreator); helper.addEventListener(new Playable.DefaultEventListener() { @@ -2833,7 +2887,13 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy @Override public void play() { if (helper != null && mediaUri != null) { - helper.play(); + if (!isPlaying() && isManuallyPaused) { + helper.play(); + pause(); + helper.setVolume(volume); + } else { + helper.play(); + } } } @@ -2853,11 +2913,13 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy helper.release(); helper = null; } + isManuallyPaused = false; + container = null; } @Override public boolean wantsToPlay() { - return canPlayVideo && mediaUri != null && ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset; + return canPlayVideo && ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset; } @Override @@ -4296,6 +4358,12 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy ImageView muteButton; @BindView(R.id.fullscreen_exo_playback_control_view) ImageView fullscreenButton; + @BindView(R.id.exo_pause) + ImageView pauseButton; + @BindView(R.id.exo_play) + ImageView playButton; + @BindView(R.id.exo_progress) + DefaultTimeBar progressBar; @BindView(R.id.bottom_constraint_layout_item_post_card_2_video_autoplay) ConstraintLayout bottomConstraintLayout; @BindView(R.id.plus_button_item_post_card_2_video_autoplay) @@ -4314,10 +4382,13 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy View divider; @Nullable + Container container; + @Nullable ExoPlayerViewHelper helper; private Uri mediaUri; private float volume; public Call<String> fetchGfycatOrStreamableVideoCall; + private boolean isManuallyPaused; PostCard2VideoAutoplayViewHolder(View itemView) { super(itemView); @@ -4366,6 +4437,36 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy } }); + pauseButton.setOnClickListener(view -> { + pause(); + isManuallyPaused = true; + savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo()); + }); + + playButton.setOnClickListener(view -> { + isManuallyPaused = false; + play(); + }); + + progressBar.addListener(new TimeBar.OnScrubListener() { + @Override + public void onScrubStart(TimeBar timeBar, long position) { + + } + + @Override + public void onScrubMove(TimeBar timeBar, long position) { + + } + + @Override + public void onScrubStop(TimeBar timeBar, long position, boolean canceled) { + if (!canceled) { + savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo()); + } + } + }); + fullscreenButton.setOnClickListener(view -> { int position = getBindingAdapterPosition(); if (position < 0) { @@ -4430,6 +4531,10 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy volume = 0f; } + private void savePlaybackInfo(int order, @Nullable PlaybackInfo playbackInfo) { + if (container != null) container.savePlaybackInfo(order, playbackInfo); + } + @NonNull @Override public View getPlayerView() { @@ -4447,6 +4552,9 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy if (mediaUri == null) { return; } + if (this.container == null) { + this.container = container; + } if (helper == null) { helper = new ExoPlayerViewHelper(this, mediaUri, null, mExoCreator); helper.addEventListener(new Playable.DefaultEventListener() { @@ -4488,7 +4596,13 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy @Override public void play() { if (helper != null && mediaUri != null) { - helper.play(); + if (!isPlaying() && isManuallyPaused) { + helper.play(); + pause(); + helper.setVolume(volume); + } else { + helper.play(); + } } } @@ -4508,11 +4622,13 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy helper.release(); helper = null; } + isManuallyPaused = false; + container = null; } @Override public boolean wantsToPlay() { - return canPlayVideo && mediaUri != null && ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset; + return canPlayVideo && ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset; } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java index cbafd113..62974d8f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -45,7 +45,9 @@ import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.target.Target; import com.google.android.exoplayer2.Tracks; import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; +import com.google.android.exoplayer2.ui.DefaultTimeBar; import com.google.android.exoplayer2.ui.PlayerView; +import com.google.android.exoplayer2.ui.TimeBar; import com.google.common.collect.ImmutableList; import com.libRG.CustomTextView; @@ -656,7 +658,9 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler } else { ((PostDetailVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1); } - ((PostDetailVideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (mPost.isNSFW() && mMuteNSFWVideo) ? 0f : 1f); + if (!((PostDetailVideoAutoplayViewHolder) holder).isManuallyPaused) { + ((PostDetailVideoAutoplayViewHolder) holder).setVolume((mMuteAutoplayingVideos || (mPost.isNSFW() && mMuteNSFWVideo)) ? 0f : 1f); + } if (mPost.isGfycat() || mPost.isRedgifs() && !mPost.isLoadGfycatOrStreamableVideoSuccess()) { ((PostDetailVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall = @@ -994,7 +998,9 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler } ((PostDetailVideoAutoplayViewHolder) holder).mErrorLoadingGfycatImageView.setVisibility(View.GONE); ((PostDetailVideoAutoplayViewHolder) holder).muteButton.setVisibility(View.GONE); - ((PostDetailVideoAutoplayViewHolder) holder).resetVolume(); + if (!((PostDetailVideoAutoplayViewHolder) holder).isManuallyPaused) { + ((PostDetailVideoAutoplayViewHolder) holder).resetVolume(); + } mGlide.clear(((PostDetailVideoAutoplayViewHolder) holder).previewImageView); ((PostDetailVideoAutoplayViewHolder) holder).previewImageView.setVisibility(View.GONE); } else if (holder instanceof PostDetailVideoAndGifPreviewHolder) { @@ -1559,6 +1565,12 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler ImageView muteButton; @BindView(R.id.fullscreen_exo_playback_control_view) ImageView fullscreenButton; + @BindView(R.id.exo_pause) + ImageView pauseButton; + @BindView(R.id.exo_play) + ImageView playButton; + @BindView(R.id.exo_progress) + DefaultTimeBar progressBar; @BindView(R.id.content_markdown_view_item_post_detail_video_autoplay) RecyclerView mContentMarkdownView; @BindView(R.id.bottom_constraint_layout_item_post_detail_video_autoplay) @@ -1576,9 +1588,12 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler @BindView(R.id.share_button_item_post_detail_video_autoplay) ImageView mShareButton; @Nullable + Container container; + @Nullable ExoPlayerViewHelper helper; private Uri mediaUri; private float volume; + private boolean isManuallyPaused; public PostDetailVideoAutoplayViewHolder(@NonNull View itemView) { super(itemView); @@ -1662,6 +1677,36 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler } }); + pauseButton.setOnClickListener(view -> { + pause(); + isManuallyPaused = true; + savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo()); + }); + + playButton.setOnClickListener(view -> { + isManuallyPaused = false; + play(); + }); + + progressBar.addListener(new TimeBar.OnScrubListener() { + @Override + public void onScrubStart(TimeBar timeBar, long position) { + + } + + @Override + public void onScrubMove(TimeBar timeBar, long position) { + + } + + @Override + public void onScrubStop(TimeBar timeBar, long position, boolean canceled) { + if (!canceled) { + savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo()); + } + } + }); + previewImageView.setOnClickListener(view -> fullscreenButton.performClick()); playerView.setOnClickListener(view -> { if (mEasierToWatchInFullScreen && playerView.isControllerVisible()) { @@ -1682,6 +1727,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler volume = 0f; } + private void savePlaybackInfo(int order, @Nullable PlaybackInfo playbackInfo) { + if (container != null) container.savePlaybackInfo(order, playbackInfo); + } + @NonNull @Override public View getPlayerView() { @@ -1699,6 +1748,9 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler if (mediaUri == null) { return; } + if (this.container == null) { + this.container = container; + } if (helper == null) { helper = new ExoPlayerViewHelper(this, mediaUri, null, mExoCreator); helper.addEventListener(new Playable.DefaultEventListener() { @@ -1736,7 +1788,15 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler @Override public void play() { - if (helper != null && mediaUri != null) helper.play(); + if (helper != null && mediaUri != null) { + if (!isPlaying() && isManuallyPaused) { + helper.play(); + pause(); + helper.setVolume(volume); + } else { + helper.play(); + } + } } @Override @@ -1755,6 +1815,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler helper.release(); helper = null; } + container = null; } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java index 99b45815..74ad401c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -47,7 +47,9 @@ import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.target.Target; import com.google.android.exoplayer2.Tracks; import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; +import com.google.android.exoplayer2.ui.DefaultTimeBar; import com.google.android.exoplayer2.ui.PlayerView; +import com.google.android.exoplayer2.ui.TimeBar; import com.google.common.collect.ImmutableList; import com.libRG.CustomTextView; @@ -739,10 +741,12 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } else { ((PostVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1); } - if (mFragment.getMasterMutingOption() == null) { - ((PostVideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (post.isNSFW() && mMuteNSFWVideo) ? 0f : 1f); - } else { - ((PostVideoAutoplayViewHolder) holder).setVolume(mFragment.getMasterMutingOption() ? 0f : 1f); + if (!((PostVideoAutoplayViewHolder) holder).isManuallyPaused) { + if (mFragment.getMasterMutingOption() == null) { + ((PostVideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (post.isNSFW() && mMuteNSFWVideo) ? 0f : 1f); + } else { + ((PostVideoAutoplayViewHolder) holder).setVolume(mFragment.getMasterMutingOption() ? 0f : 1f); + } } if ((post.isGfycat() || post.isRedgifs()) && !post.isLoadGfycatOrStreamableVideoSuccess()) { @@ -920,10 +924,12 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } else { ((PostCard2VideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1); } - if (mFragment.getMasterMutingOption() == null) { - ((PostCard2VideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (post.isNSFW() && mMuteNSFWVideo) ? 0f : 1f); - } else { - ((PostCard2VideoAutoplayViewHolder) holder).setVolume(mFragment.getMasterMutingOption() ? 0f : 1f); + if (!((PostCard2VideoAutoplayViewHolder) holder).isManuallyPaused) { + if (mFragment.getMasterMutingOption() == null) { + ((PostCard2VideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (post.isNSFW() && mMuteNSFWVideo) ? 0f : 1f); + } else { + ((PostCard2VideoAutoplayViewHolder) holder).setVolume(mFragment.getMasterMutingOption() ? 0f : 1f); + } } if ((post.isGfycat() || post.isRedgifs()) && !post.isLoadGfycatOrStreamableVideoSuccess()) { @@ -1898,7 +1904,9 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } ((PostVideoAutoplayViewHolder) holder).errorLoadingGfycatImageView.setVisibility(View.GONE); ((PostVideoAutoplayViewHolder) holder).muteButton.setVisibility(View.GONE); - ((PostVideoAutoplayViewHolder) holder).resetVolume(); + if (!((PostVideoAutoplayViewHolder) holder).isManuallyPaused) { + ((PostVideoAutoplayViewHolder) holder).resetVolume(); + } mGlide.clear(((PostVideoAutoplayViewHolder) holder).previewImageView); ((PostVideoAutoplayViewHolder) holder).previewImageView.setVisibility(View.GONE); } else if (holder instanceof PostWithPreviewTypeViewHolder) { @@ -2777,6 +2785,12 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ImageView muteButton; @BindView(R.id.fullscreen_exo_playback_control_view) ImageView fullscreenButton; + @BindView(R.id.exo_pause) + ImageView pauseButton; + @BindView(R.id.exo_play) + ImageView playButton; + @BindView(R.id.exo_progress) + DefaultTimeBar progressBar; @BindView(R.id.bottom_constraint_layout_item_post_video_type_autoplay) ConstraintLayout bottomConstraintLayout; @BindView(R.id.plus_button_item_post_video_type_autoplay) @@ -2793,10 +2807,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ImageView shareButton; @Nullable + Container container; + @Nullable ExoPlayerViewHelper helper; private Uri mediaUri; private float volume; public Call<String> fetchGfycatOrStreamableVideoCall; + private boolean isManuallyPaused; PostVideoAutoplayViewHolder(View itemView) { super(itemView); @@ -2889,6 +2906,36 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } }); + pauseButton.setOnClickListener(view -> { + pause(); + isManuallyPaused = true; + savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo()); + }); + + playButton.setOnClickListener(view -> { + isManuallyPaused = false; + play(); + }); + + progressBar.addListener(new TimeBar.OnScrubListener() { + @Override + public void onScrubStart(TimeBar timeBar, long position) { + + } + + @Override + public void onScrubMove(TimeBar timeBar, long position) { + + } + + @Override + public void onScrubStop(TimeBar timeBar, long position, boolean canceled) { + if (!canceled) { + savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo()); + } + } + }); + previewImageView.setOnClickListener(view -> fullscreenButton.performClick()); videoPlayer.setOnClickListener(view -> { @@ -2910,6 +2957,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie volume = 0f; } + private void savePlaybackInfo(int order, @Nullable PlaybackInfo playbackInfo) { + if (container != null) container.savePlaybackInfo(order, playbackInfo); + } + @NonNull @Override public View getPlayerView() { @@ -2927,6 +2978,9 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie if (mediaUri == null) { return; } + if (this.container == null) { + this.container = container; + } if (helper == null) { helper = new ExoPlayerViewHelper(this, mediaUri, null, mExoCreator); helper.addEventListener(new Playable.DefaultEventListener() { @@ -2968,7 +3022,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie @Override public void play() { if (helper != null && mediaUri != null) { - helper.play(); + if (!isPlaying() && isManuallyPaused) { + helper.play(); + pause(); + helper.setVolume(volume); + } else { + helper.play(); + } } } @@ -2988,11 +3048,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie helper.release(); helper = null; } + isManuallyPaused = false; + container = null; } @Override public boolean wantsToPlay() { - return canPlayVideo && mediaUri != null && ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset; + return canPlayVideo && ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset; } @Override @@ -4497,6 +4559,12 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ImageView muteButton; @BindView(R.id.fullscreen_exo_playback_control_view) ImageView fullscreenButton; + @BindView(R.id.exo_pause) + ImageView pauseButton; + @BindView(R.id.exo_play) + ImageView playButton; + @BindView(R.id.exo_progress) + DefaultTimeBar progressBar; @BindView(R.id.bottom_constraint_layout_item_post_card_2_video_autoplay) ConstraintLayout bottomConstraintLayout; @BindView(R.id.plus_button_item_post_card_2_video_autoplay) @@ -4515,10 +4583,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie View divider; @Nullable + Container container; + @Nullable ExoPlayerViewHelper helper; private Uri mediaUri; private float volume; public Call<String> fetchGfycatOrStreamableVideoCall; + private boolean isManuallyPaused; PostCard2VideoAutoplayViewHolder(View itemView) { super(itemView); @@ -4611,6 +4682,36 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } }); + pauseButton.setOnClickListener(view -> { + pause(); + isManuallyPaused = true; + savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo()); + }); + + playButton.setOnClickListener(view -> { + isManuallyPaused = false; + play(); + }); + + progressBar.addListener(new TimeBar.OnScrubListener() { + @Override + public void onScrubStart(TimeBar timeBar, long position) { + + } + + @Override + public void onScrubMove(TimeBar timeBar, long position) { + + } + + @Override + public void onScrubStop(TimeBar timeBar, long position, boolean canceled) { + if (!canceled) { + savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo()); + } + } + }); + previewImageView.setOnClickListener(view -> fullscreenButton.performClick()); videoPlayer.setOnClickListener(view -> { @@ -4632,6 +4733,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie volume = 0f; } + private void savePlaybackInfo(int order, @Nullable PlaybackInfo playbackInfo) { + if (container != null) container.savePlaybackInfo(order, playbackInfo); + } + @NonNull @Override public View getPlayerView() { @@ -4649,6 +4754,9 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie if (mediaUri == null) { return; } + if (this.container == null) { + this.container = container; + } if (helper == null) { helper = new ExoPlayerViewHelper(this, mediaUri, null, mExoCreator); helper.addEventListener(new Playable.DefaultEventListener() { @@ -4690,7 +4798,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie @Override public void play() { if (helper != null && mediaUri != null) { - helper.play(); + if (!isPlaying() && isManuallyPaused) { + helper.play(); + pause(); + helper.setVolume(volume); + } else { + helper.play(); + } } } @@ -4710,11 +4824,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie helper.release(); helper = null; } + isManuallyPaused = false; + container = null; } @Override public boolean wantsToPlay() { - return canPlayVideo && mediaUri != null && ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset; + return canPlayVideo && ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset; } @Override |