Fix several Gif MP4 UX issues.

This commit is contained in:
Alex Hart
2021-06-09 10:23:41 -03:00
parent 2029ea378f
commit 335ff61011
11 changed files with 75 additions and 50 deletions

View File

@@ -24,21 +24,23 @@ public abstract class MediaPreviewFragment extends Fragment {
static final String DATA_SIZE = "DATA_SIZE";
static final String DATA_CONTENT_TYPE = "DATA_CONTENT_TYPE";
static final String AUTO_PLAY = "AUTO_PLAY";
static final String VIDEO_GIF = "VIDEO_GIF";
private AttachmentId attachmentId;
protected Events events;
public static MediaPreviewFragment newInstance(@NonNull Attachment attachment, boolean autoPlay) {
return newInstance(attachment.getUri(), attachment.getContentType(), attachment.getSize(), autoPlay);
return newInstance(attachment.getUri(), attachment.getContentType(), attachment.getSize(), autoPlay, attachment.isVideoGif());
}
public static MediaPreviewFragment newInstance(@NonNull Uri dataUri, @NonNull String contentType, long size, boolean autoPlay) {
public static MediaPreviewFragment newInstance(@NonNull Uri dataUri, @NonNull String contentType, long size, boolean autoPlay, boolean isVideoGif) {
Bundle args = new Bundle();
args.putParcelable(MediaPreviewFragment.DATA_URI, dataUri);
args.putString(MediaPreviewFragment.DATA_CONTENT_TYPE, contentType);
args.putLong(MediaPreviewFragment.DATA_SIZE, size);
args.putBoolean(MediaPreviewFragment.AUTO_PLAY, autoPlay);
args.putBoolean(MediaPreviewFragment.VIDEO_GIF, isVideoGif);
MediaPreviewFragment fragment = createCorrectFragmentType(contentType);

View File

@@ -19,6 +19,7 @@ public final class VideoMediaPreviewFragment extends MediaPreviewFragment {
private static final String TAG = Log.tag(VideoMediaPreviewFragment.class);
private VideoPlayer videoView;
private boolean isVideoGif;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
@@ -35,6 +36,8 @@ public final class VideoMediaPreviewFragment extends MediaPreviewFragment {
long size = arguments.getLong(DATA_SIZE);
boolean autoPlay = arguments.getBoolean(AUTO_PLAY);
isVideoGif = arguments.getBoolean(VIDEO_GIF);
if (!MediaUtil.isVideo(contentType)) {
throw new AssertionError("This fragment can only display video");
}
@@ -44,6 +47,11 @@ public final class VideoMediaPreviewFragment extends MediaPreviewFragment {
videoView.setWindow(requireActivity().getWindow());
videoView.setVideoSource(new VideoSlide(getContext(), uri, size, false), autoPlay);
if (isVideoGif) {
videoView.hideControls();
videoView.loopForever();
}
videoView.setOnClickListener(v -> events.singleTapOnMedia());
return itemView;
@@ -56,6 +64,14 @@ public final class VideoMediaPreviewFragment extends MediaPreviewFragment {
}
}
@Override
public void onResume() {
super.onResume();
if (videoView != null && isVideoGif) {
videoView.play();
}
}
@Override
public void pause() {
if (videoView != null) {
@@ -65,6 +81,6 @@ public final class VideoMediaPreviewFragment extends MediaPreviewFragment {
@Override
public View getPlaybackControls() {
return videoView != null ? videoView.getControlView() : null;
return videoView != null && !isVideoGif ? videoView.getControlView() : null;
}
}