Show a preview image before autoplaying video is loaded.

This commit is contained in:
Alex Ning 2020-07-06 22:14:58 +08:00
parent 3ef4b90a63
commit ba2a219168
3 changed files with 28 additions and 2 deletions

View File

@ -522,6 +522,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
if (holder instanceof PostVideoAutoplayViewHolder) { if (holder instanceof PostVideoAutoplayViewHolder) {
((PostVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) post.getPreviewWidth() / post.getPreviewHeight()); ((PostVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) post.getPreviewWidth() / post.getPreviewHeight());
((PostVideoAutoplayViewHolder) holder).previewImageView.setVisibility(View.VISIBLE);
mGlide.load(post.getPreviewUrl()).apply(RequestOptions.noTransformation()).into(((PostVideoAutoplayViewHolder) holder).previewImageView);
((PostVideoAutoplayViewHolder) holder).bindVideoUri(Uri.parse(post.getVideoUrl())); ((PostVideoAutoplayViewHolder) holder).bindVideoUri(Uri.parse(post.getVideoUrl()));
} else if (holder instanceof PostVideoAndGifPreviewViewHolder) { } else if (holder instanceof PostVideoAndGifPreviewViewHolder) {
if (post.getPostType() == Post.VIDEO_TYPE) { if (post.getPostType() == Post.VIDEO_TYPE) {
@ -1351,6 +1353,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
if (holder instanceof PostVideoAutoplayViewHolder) { if (holder instanceof PostVideoAutoplayViewHolder) {
((PostVideoAutoplayViewHolder) holder).muteButton.setVisibility(View.GONE); ((PostVideoAutoplayViewHolder) holder).muteButton.setVisibility(View.GONE);
((PostVideoAutoplayViewHolder) holder).resetVolume(); ((PostVideoAutoplayViewHolder) holder).resetVolume();
mGlide.clear(((PostVideoAutoplayViewHolder) holder).previewImageView);
((PostVideoAutoplayViewHolder) holder).previewImageView.setVisibility(View.GONE);
} else if (holder instanceof PostImageAndGifAutoplayViewHolder) { } else if (holder instanceof PostImageAndGifAutoplayViewHolder) {
mGlide.clear(((PostImageAndGifAutoplayViewHolder) holder).imageView); mGlide.clear(((PostImageAndGifAutoplayViewHolder) holder).imageView);
((PostImageAndGifAutoplayViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.FIT_START); ((PostImageAndGifAutoplayViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.FIT_START);
@ -1884,6 +1888,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
CustomTextView awardsTextView; CustomTextView awardsTextView;
@BindView(R.id.aspect_ratio_frame_layout_item_post_video_type_autoplay) @BindView(R.id.aspect_ratio_frame_layout_item_post_video_type_autoplay)
AspectRatioFrameLayout aspectRatioFrameLayout; AspectRatioFrameLayout aspectRatioFrameLayout;
@BindView(R.id.preview_image_view_item_post_video_type_autoplay)
ImageView previewImageView;
@BindView(R.id.player_view_item_post_video_type_autoplay) @BindView(R.id.player_view_item_post_video_type_autoplay)
PlayerView videoPlayer; PlayerView videoPlayer;
@BindView(R.id.mute_exo_playback_control_view) @BindView(R.id.mute_exo_playback_control_view)
@ -2024,6 +2030,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
public void onCues(List<Cue> cues) { public void onCues(List<Cue> cues) {
} }
@Override
public void onRenderedFirstFrame() {
mGlide.clear(previewImageView);
previewImageView.setVisibility(View.GONE);
}
}); });
} }
helper.initialize(container, playbackInfo); helper.initialize(container, playbackInfo);
@ -2054,7 +2066,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
@Override @Override
public boolean wantsToPlay() { public boolean wantsToPlay() {
return ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= 0.85; return ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= 0.75;
} }
@Override @Override

View File

@ -202,6 +202,13 @@
android:background="#000000" android:background="#000000"
app:resize_mode="fixed_width"> app:resize_mode="fixed_width">
<ImageView
android:id="@+id/preview_image_view_item_post_detail_video_autoplay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitStart"
android:visibility="gone" />
<com.google.android.exoplayer2.ui.PlayerView <com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/player_view_item_post_detail_video_autoplay" android:id="@+id/player_view_item_post_detail_video_autoplay"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -208,6 +208,13 @@
android:layout_height="match_parent" android:layout_height="match_parent"
app:controller_layout_id="@layout/exo_autoplay_playback_control_view" /> app:controller_layout_id="@layout/exo_autoplay_playback_control_view" />
<ImageView
android:id="@+id/preview_image_view_item_post_video_type_autoplay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitStart"
android:visibility="gone" />
</com.google.android.exoplayer2.ui.AspectRatioFrameLayout> </com.google.android.exoplayer2.ui.AspectRatioFrameLayout>
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout