From e06222733c0bfb2b5b577bd17fc1a1079c0cc212 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 23 Jul 2023 17:31:35 +0200 Subject: [PATCH] Fix - Videos are played simultaneously --- .../mastodon/ui/fragment/media/FragmentMedia.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/media/FragmentMedia.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/media/FragmentMedia.java index 02f49b223..bedc2122c 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/media/FragmentMedia.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/media/FragmentMedia.java @@ -71,9 +71,12 @@ public class FragmentMedia extends Fragment { private FragmentSlideMediaBinding binding; private SlidrInterface slidrInterface; + private boolean visible = false; + public FragmentMedia() { } + @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -236,6 +239,7 @@ public class FragmentMedia extends Fragment { } } + private void loadVideo(String url, String type) { if (binding == null || !isAdded() || getActivity() == null || url == null) { return; @@ -267,7 +271,7 @@ public class FragmentMedia extends Fragment { binding.mediaPicture.setVisibility(View.GONE); player.setMediaSource(videoSource); player.prepare(); - player.setPlayWhenReady(true); + player.setPlayWhenReady(visible); player.addListener(new Player.Listener() { @Override public void onPlayerError(@NonNull PlaybackException error) { @@ -301,6 +305,7 @@ public class FragmentMedia extends Fragment { @Override public void onPause() { super.onPause(); + visible = false; if (player != null) { player.setPlayWhenReady(false); } @@ -318,9 +323,11 @@ public class FragmentMedia extends Fragment { } } + @Override public void onResume() { super.onResume(); + visible = true; if (player != null) { player.setPlayWhenReady(true); }