kopia lustrzana https://github.com/ryukoposting/Signal-Android
Fix video playback starting when off screen in media viewer.
rodzic
ebdfa88882
commit
055b4691d7
|
@ -29,36 +29,6 @@ public abstract class MediaPreviewFragment extends Fragment {
|
|||
private AttachmentId attachmentId;
|
||||
protected Events events;
|
||||
|
||||
public static MediaPreviewFragment newInstance(@NonNull Attachment attachment, boolean 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, 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);
|
||||
|
||||
fragment.setArguments(args);
|
||||
|
||||
return fragment;
|
||||
}
|
||||
|
||||
private static MediaPreviewFragment createCorrectFragmentType(@NonNull String contentType) {
|
||||
if (MediaUtil.isVideo(contentType)) {
|
||||
return new VideoMediaPreviewFragment();
|
||||
} else if (MediaUtil.isImageType(contentType)) {
|
||||
return new ImageMediaPreviewFragment();
|
||||
} else {
|
||||
throw new AssertionError("Unexpected media type: " + contentType);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(@NonNull Context context) {
|
||||
super.onAttach(context);
|
||||
|
@ -78,6 +48,7 @@ public abstract class MediaPreviewFragment extends Fragment {
|
|||
checkMediaStillAvailable();
|
||||
}
|
||||
|
||||
public void autoPlayIfNeeded() {}
|
||||
public abstract void cleanUp();
|
||||
public abstract void pause();
|
||||
public abstract void setBottomButtonControls(MediaPreviewPlayerControlView playerControlView);
|
||||
|
|
|
@ -28,7 +28,7 @@ class MediaPreviewV2Adapter(fragment: Fragment) : FragmentStateAdapter(fragment)
|
|||
MediaPreviewFragment.DATA_URI to attachment.uri,
|
||||
MediaPreviewFragment.DATA_CONTENT_TYPE to contentType,
|
||||
MediaPreviewFragment.DATA_SIZE to attachment.size,
|
||||
MediaPreviewFragment.AUTO_PLAY to true,
|
||||
MediaPreviewFragment.AUTO_PLAY to attachment.isVideoGif,
|
||||
MediaPreviewFragment.VIDEO_GIF to attachment.isVideoGif,
|
||||
)
|
||||
val fragment = if (MediaUtil.isVideo(contentType)) {
|
||||
|
|
|
@ -297,6 +297,7 @@ class MediaPreviewV2Fragment : LoggingFragment(R.layout.fragment_media_preview_v
|
|||
forward(currentItem)
|
||||
}
|
||||
currentFragment?.setBottomButtonControls(binding.mediaPreviewPlaybackControls)
|
||||
currentFragment?.autoPlayIfNeeded()
|
||||
}
|
||||
|
||||
private fun bindAlbumRail(albumThumbnailMedia: List<Media>, currentItem: MediaTable.MediaRecord) {
|
||||
|
|
|
@ -31,14 +31,7 @@ public final class VideoMediaPreviewFragment extends MediaPreviewFragment {
|
|||
private boolean isVideoGif;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState)
|
||||
{
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View itemView = inflater.inflate(R.layout.media_preview_video_fragment, container, false);
|
||||
Bundle arguments = requireArguments();
|
||||
Uri uri = arguments.getParcelable(DATA_URI);
|
||||
|
@ -111,13 +104,6 @@ public final class VideoMediaPreviewFragment extends MediaPreviewFragment {
|
|||
cleanUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanUp() {
|
||||
if (videoView != null) {
|
||||
videoView.cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
@ -131,6 +117,20 @@ public final class VideoMediaPreviewFragment extends MediaPreviewFragment {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void autoPlayIfNeeded() {
|
||||
if (videoView != null && videoView.getPlaybackPosition() < videoView.getDuration()) {
|
||||
videoView.play();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanUp() {
|
||||
if (videoView != null) {
|
||||
videoView.cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause() {
|
||||
if (videoView != null) {
|
||||
|
|
Ładowanie…
Reference in New Issue